草庐IT

java - JSR - Spring Boot 的 Spring @RestController 的 349 bean 验证

我正在使用SpringBoot1.5.2.RELEASE并且无法为@RequestParam合并JSR-349(bean验证1.1)&@PathVariable在方法本身。对于POST请求,如果方法参数是JavaPOJO,则用@Valid注释该参数工作正常但注释@RequestParam&@PathVariable用类似@NotEmpty的东西,@Email不工作。我已经用Spring的@Validated注释了Controller类关于SO的问题很多,我在thisanswer上发表了评论它不适合我。SpringBoot包括-validation-api-1.1.0.Final.jar

java - Spring Boot 中不可解析的父 POM

我正在尝试为SpringBoot应用程序设置Maven项目,但在尝试保存pom.xml文件时出现以下问题:Projectbuilderror:Non-resolvableparentPOMforio.javabrains.springbootquickstart:course-api:0.0.1-SNAPSHOT:Couldnotfindartifactorg.springframework.boot:spring-boot-starter-parent:pom:${revision}incentral(https://repo.maven.apache.org/maven2)and'

java - 抛出 RuntimeException 会导致事务回滚,但 Spring Boot 应用程序中不会出现异常

在下面的代码中,抛出一个Exception不会回滚事务,但是抛出一个RuntimeException会。@ServicepublicclassHelloService{@AutowiredprotectedCustomerRepositoryrepository;@Transactionalpublicvoidrun()throwsException{repository.save(newCustomer("Jack","Bauer"));thrownewRuntimeException("Kabooom!!!");//Transactionisrolledback.Databasei

java - Spring Boot viewControllerHandlerMapping配置

这是我的Application.java的示例要点@Configuration@EnableAutoConfiguration@ComponentScan(basePackages="org.com.app.client.controller")@EnableJpaRepositories(basePackages="org.com.app")@EntityScan(basePackages="org.com.app.model")publicclassApplicationextendsSpringBootServletInitializer{publicstaticvoidmain

java - Spring Boot Actuator - 无法禁用/信息端点

我尝试在application.yml配置文件中禁用生产环境的所有执行器端点:endpoints.enabled:false它适用于除/info之外的所有端点。如何关闭给定环境的所有端点?更新:我正在做的项目也是Eureka客户端。在StatusPageandHealthIndicator(http://cloud.spring.io/spring-cloud-netflix/spring-cloud-netflix.html)部分的SpringCloudNetflix文档中,它说“Eureka实例分别默认为“/info”和“/health”。是否有任何解决方案可以禁用这些端点?我能够

java - 如何在 Spring Boot 应用程序启动时启动 H2 TCP 服务器?

通过将以下行添加到SpringBootServletInitializermain方法中,我可以在将应用程序作为SpringBoot应用程序运行时启动H2TCP服务器(文件中的数据库):@SpringBootApplicationpublicclassNatiaApplicationextendsSpringBootServletInitializer{publicstaticvoidmain(String[]args){Server.createTcpServer().start();SpringApplication.run(NatiaApplication.class,args)

java - 无法使用 Spring Boot 和基于 Java 的配置注入(inject) UserDetailsManager

我有一个springbootwebapp,它使用基于Java的配置来配置JdbcUserDetailsManager:@Configuration@EnableWebMvcSecuritypublicclassSecurityConfigextendsWebSecurityConfigurerAdapter{@AutowiredprotectedDataSourcedataSource;@AutowiredpublicvoidconfigAuthentication(AuthenticationManagerBuilderauth)throwsException{auth.jdbcAu

java - Spring-Boot-Jersey 设置 CORS

我通过两台不同的服务器为我的前端和后端提供服务。现在我正试图让CORS在Spring-Boot-Jersey后端上工作。我尝试了在互联网上可以找到的所有方法,但似乎没有任何效果,或者我遗漏了一些东西。我当前的设置使用ContainerResponseFilter。我尝试使用@Provider自动注册,并在Jersey配置中手动注册。容器响应过滤器@ProviderpublicclassCORSFilterimplementsContainerResponseFilter{@Overridepublicvoidfilter(ContainerRequestContextrequest,C

java - Spring Boot 日志记录 - 每个日志条目开头的无关连字符

我正在尝试使用默认的logback配置从SpringBoot1.3.5.RELEASE的控制台和文件日志中删除前导连字符。记录模式如下:logging:pattern:console:'%d{yyyy-MM-ddHH:mm:ss.SSS}%clr([${spring.application.name}]){red}%clr(%5p)%clr(${PID:-}){magenta}%clr(---){faint}%X{req.requestId}%clr([%15.15t]){faint}%clr(%-40.40logger{39}){cyan}%clr(:){faint}%m%n${LO

java - 在 spring boot 中通过动态键读取属性

我想知道在SpringBoot中是否有任何方法可以使用动态键从属性文件中读取属性值。我知道属性可以放在application.properties中,并且可以使用@Value("propertyKey")读取,但我的key将是动态的。我知道@PropertySource可以读取属性值,而且我可以动态构造我的键。那么SpringBoot有没有提供什么方式呢? 最佳答案 你可以使用:@AutowiredprivateEnvironmentenv;然后从代码加载属性:env.getProperty("your.property")