草庐IT

java - 在 spring boot 中定义重要凭据的最佳方式

在使用SpringBoot应用时,我们会根据不同的环境使用不同的application.properties文件。我们放置了重要的凭据,例如:数据库配置、服务器IP、管理员用户名/密码等。我担心如果有人获得我们的应用程序属性并获得所有重要细节会发生什么。有没有什么好的方法可以将重要的凭据放在某个地方,并在我们基于环境的SpringBoot应用程序中获取它们? 最佳答案 很多技巧使用token替换(mavenreplacor)application.propertiesspring.datasource.password=#MY_DB

java - 使用 Spring boot CrudRepository 过滤数据

我有一个简单的REST服务,它使用Springboot访问数据CrudRepository.这个存储库已经实现了这样的分页和排序功能:publicinterfaceFlightRepositoryextendsCrudRepository{ListfindAll(Pageablepageable);}调用它:Sortsort=newSort(direction,ordering);PageRequestpage=newPageRequest(xoffset,xbase,sort);returnflightRepo.findAll(page);我还想向这个存储库添加过滤(例如只返回带有i

java - 使用 Spring-boot 进行安全配置

我为Spring-Boot创建了一个SpringSecurity配置类。我的登录页面有资源css、js和ico文件。出于安全原因,资源被拒绝并每次都重定向到登录页面。为什么EnableWebMVCSecurity不添加Classpath资源位置。在更改第二个代码段中的代码后,添加了IClasspath资源位置。不明白我缺少第一个代码片段中的资源。@Configuration/**EnableSpringSecurity’swebsecuritysupportandprovidetheSpringMVCintegration*ItalsoextendsWebSecurityConfigu

java - 您如何在 Bootstrap 文件中正确设置不同的 Spring 配置文件(让 Spring Boot 以不同的云配置服务器为目标)?

我们每个环境都有不同的配置服务器。每个springboot应用程序都应该以其相应的配置服务器为目标。我试图通过在bootstrap.properties文件中设置配置文件来实现这一点,例如:spring.application.name=app-namespring.cloud.config.uri=http://default-config-server.com---spring.profiles=devspring.cloud.config.uri=http://dev-config-server.com---spring.profiles=stagespring.cloud.co

java - 带有 Spring Boot 1.4 : Dependencies not injected when using @SpringBootTest and @RunWith(SpringRunner. 类的 cucumber )

我正在编写一个新应用程序并尝试使用Cucumber和SpringBoot1.4进行BDD。工作代码如下所示:@SpringBootApplicationpublicclassApplication{@BeanMyServicemyService(){returnnewMyService();}publicstaticvoidmain(String[]args){SpringApplication.run(Application.class,args);}}publicclassMyService{}测试代码如下:@RunWith(Cucumber.class)publicclassRu

java - Rest 服务中的 Spring Boot 自定义异常

我在基于SpringBoot的Rest服务中定义了一个全局异常处理:@ControllerAdvicepublicclassGlobalExceptionController{privatefinalLoggerLOG=LoggerFactory.getLogger(getClass());@ResponseStatus(value=HttpStatus.INTERNAL_SERVER_ERROR,reason="Internalapplicationerror")@ExceptionHandler({ServiceException.class})@ResponseBodypubli

java - Spring Boot Elasticsearch 配置

我有一个工作的SpringBootElasticsearch应用程序,它使用两个配置文件之一:application.dev.properties或application.prod.properties。那部分工作正常。我在让外部elasticsearch从application.xxx.properties中读取时遇到问题。这个有效:@Configuration@PropertySource(value="classpath:config/elasticsearch.properties")publicclassElasticsearchConfiguration{@Resource

java - Elasticsearch Spring boot 集成测试

我正在寻找将嵌入式elasticsearch添加到我的springboot集成测试中的方法。我查看了Elasticsearch集成测试,但它不能与springboot一起工作,因为两者应该使用不同的测试运行器。不幸的是,我有一个如下的类测试,它不能正常工作,但有错误:java.lang.IllegalStateException:Nocontextinformationforthread:Thread[id=1,name=main,state=RUNNABLE,group=main].Isthisthreadrunningunderaclasscom.carrotsearch.rand

java - Spring Boot 测试配置

我有一个springboot应用程序,其主类如下:@SpringBootApplicationpublicclassApplication{publicstaticvoidmain(String[]args)throwsException{SpringApplication.run(Application.class,args);}}现在我想测试我的服务并创建了一个基础测试类:@SpringApplicationConfiguration(Application.class)publicabstractclassTestBase{}当我运行测试时出现异常:Causedby:java.l

java - 如何在 Spring Boot 中从 application.properties 分配注释值?

我有一个带有鉴别器公式的实体/模型,现在我正在分配一个鉴别器公式,如下例所示,@Entity@DiscriminatorFormula("type")classStudent{//code}在同样的情况下,如何在SpringBoot中从application.properties分配鉴别器值? 最佳答案 类级别注释中的表达式应该是常量,即final和static。你想要达到的目标是不可能的。您能做的最好的事情就是从常量文件而不是application.properties中读取它。 关于