将Spring Boot版本从2.0.0升级到2.1.1后,不会加载application-test.properties中定义的属性。
由于日志显示以下内容,因此配置文件已正确设置:
The following profiles are active: test
我尝试添加以下内容:
@ActiveProfiles("test")
@TestPropertySource(
locations = "classpath:application-test.properties")
@EnableConfigurationProperties
现有注释:
@RunWith(SpringRunner.class)
@SpringBootTest(classes = {TestConfiguration.class, TestMongoConfiguration.class})
TestConfiguration:
@EnableWebMvc
@AutoConfigureWebClient
@EnableJpaAuditing
@EnableJpaRepositories({"org.mycode"})
@DataJpaTest
@EnableMongoRepositories({"org.mycode"})
@DataMongoTest
@EntityScan(basePackages = "org.mycode")
// TODO Migration : there is a bug in spring data.
//@EnableMongoAuditing
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
@ComponentScan(basePackages = "org.mycode",
excludeFilters = @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = Application.class))
public class TestConfiguration {
}
注意:在运行应用程序时,它可以加载属性。看起来麻烦仅在于测试。