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'中),它添加一個屬性源和激活的配置文件密鑰。 –