3
我的活动配置文件正常工作,如果我将它们设置为虚拟机参数。我有一个测试,我想用@ActiveProfiles("local")
。@ActiveProfiles值没有被分配到配置
这里是类注解的我使用的是:
@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'中),它添加一个属性源和激活的配置文件密钥。 –