英文:
SpringJUnit4ClassRunner does not load the test properties file
问题
以下是翻译好的内容:
我正在尝试启动一个带有MapStruct实现的Spring Boot测试。我正在使用下面的配置,但是资源目录中的application.properties文件没有被读取到测试中。
如何使得下面的测试能够读取默认的属性文件?该文件存在于test/resources
目录中,其他Spring Boot测试可以加载它。
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = SpringBootExampleConfig.class)
public class SpringBootExampleTest {
@Autowired
private IMapper mapper;
@Test
public void test() {
}
@Configuration
@ComponentScan(basePackageClasses = SpringBootExampleTest.class)
public static class SpringTestConfig {
}
}
英文:
I am trying to boot up a spring boot test, with a mapstruct implementation provided.
I am using the configuration below, but the application.properties file in the resources directory is not being read into the test.
How do I get the test below to read the default properties file, the file exist in test/resources
and other spring boot tests are able to load it.
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = SpringBootExampleConfig.class)
public class SpringBootExampleTest {
@Autowired
private IMapper mapper;
@Test
public void test() {
}
@Configuration
@ComponentScan(basePackageClasses = SpringBootExampleTest.class)
public static class SpringTestConfig {
}
}
专注分享java语言的经验与见解,让所有开发者获益!
评论