如果我将它们设置为VM参数,我的活动配置文件可以正常工作。
我想使用@ActiveProfiles("local")
进行测试。
这是我正在使用的类注释:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("/jpaContext.xml")
@ActiveProfiles("local")
public class MyServiceTest {
当我尝试运行时,跟踪中出现以下内容:
Caused by: java.io.FileNotFoundException: class path resource [properties/database-configuration-${spring.profiles.active}.properties] cannot be opened because it does not exist
有什么想法,为什么这个值没有被使用?
@ActiveProfiles
注解不会在Environment
中设置spring.profiles.active
属性(它只是设置活动配置文件,这是不同的)。如果你不想按建议更改配置,你可以在测试中添加一个ApplicationContextInitializer
(在@ContextConfiguration
中),它会添加一个带有活动配置文件键的属性源。 - Dave Syer