// 脱离springboot启动环境如何加载属性文件 @Import (value = {TestProperties. class }) @EnableConfigurationProperties @ContextConfiguration (initializers = ConfigFileApplicationContextInitializer. class ) // 指定属性文件名字(可逗号分隔写多个) @TestPropertySource (properties = { "spring.config.name=test" }) @ExtendWith (SpringExtension. class ) public ?class ?NonBootButLoadPropertiesTest { ???? @Autowired ???? private ?TestProperties testProperties; ???? @Test ???? public ?void ?test() { ???????? Assert.assertEquals( "frsh" , testProperties.getValue()); ???? } } |