Java Spring引导单元测试如何加载文件
当我编写junit时,我发现@ActiveProfiles对应于我的资源目录 我不明白spring boot是如何加载资源文件的,为什么不指定@ActiveProfiles默认读取哪个应用程序文件Java Spring引导单元测试如何加载文件,java,spring,spring-boot,junit,Java,Spring,Spring Boot,Junit,当我编写junit时,我发现@ActiveProfiles对应于我的资源目录 我不明白spring boot是如何加载资源文件的,为什么不指定@ActiveProfiles默认读取哪个应用程序文件 @RunWith(SpringJUnit4ClassRunner.class) @WebAppConfiguration @SpringBootTest(类=Application.class) @ActiveProfiles(“测试”) 公共类newutorgroupiaotest{ } @Run
@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@SpringBootTest(类=Application.class)
@ActiveProfiles(“测试”)
公共类newutorgroupiaotest{
}
@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@SpringBootTest(类=Application.class)
@ActiveProfiles(“测试”)
公共类newutorgroupiaotest{
}
项目目录:
project
- src
- main
- java
- resource
- test
- java
- resource
如果使用
@Profile(“test”)
标记类,则可以通过激活测试配置文件(使用@ActiveProfiles(“test”)
、spring.profiles.active=test
)或其他多种方式确保类已加载(到应用程序上下文中)。可以使用@Profile(“test”)排除类
详情如下:
此外,通过激活配置文件,您还可以激活要拾取的属性文件…您的项目中还可能包含以下文件:
application.properties
应用程序默认属性
应用程序测试.属性
如果存在application.properties
以及application test.properties
,application.properties
构成基本配置,application test.properties
将覆盖任何现有属性,还可能提供其他配置值
如果您未提供/指定配置文件,则会激活默认
配置文件。这将导致组合应用程序.properties
+应用程序默认.properties
您将在日志中看到哪个配置文件在Spring日志输出开始时被激活。谢谢!我以前生病了,没有阅读信息,对不起。我看到了文档的配置文件和ActiveProfiles。我还阅读了SpringBootTest源代码,我理解这个问题,非常感谢