Spring boot 在不启动服务器的情况下使用Spring应用程序属性

Spring boot 在不启动服务器的情况下使用Spring应用程序属性,spring-boot,application.properties,Spring Boot,Application.properties,我们使用的是SpringBoot2.3.4 我们有一些单元测试,我们只需要加载application.properties(以及它的所有概要文件管理aso.)。 不启动完整的Spring引导服务器就可以这样做吗 编辑: 我尝试了@SpringBootTest注释,但它总是启动整个服务器,因为我引用了@SpringBootApplication类(或者它是自动引用的)。 实际上,您不需要所有其他注释,比如@ConfigurationProperties 您只需要@SpringBootApplica

我们使用的是SpringBoot2.3.4

我们有一些单元测试,我们只需要加载application.properties(以及它的所有概要文件管理aso.)。 不启动完整的Spring引导服务器就可以这样做吗

编辑:

我尝试了@SpringBootTest注释,但它总是启动整个服务器,因为我引用了@SpringBootApplication类(或者它是自动引用的)。 实际上,您不需要所有其他注释,比如@ConfigurationProperties


您只需要@SpringBootApplication(classes=AClass.class),其中AClass是没有主方法的任何类,例如您的测试类。

用@SpringBootTest注释您的测试类以加载上下文。

是的,您可以这样做,但您能用场景显示代码吗?