我有一顆豆下的「開發」簡介:如何在默認配置文件的另一個bean中使用spring profile bean?
@Bean(name="internalDL")
public Map<Client, List<String>> internalDistributionLists() {
Map<Client, List<String>> distributionLists = new HashMap<Client, List<String>>();
distributionLists.put(Client.DL_NAME, Arrays.asList("[email protected]"));
return distributionLists;
}
我需要另一個bean來使用這個bean:
@Autowired
@Qualifier("internalDL")
private Map<String, List<String>> internalMailingList;
@Bean(name="internalMailingDetails")
public Map<Client, MailingDetails> internalMailingDetails() {
Map<Client, MailingDetails> internalMailingDetails = new HashMap<Client, MailingDetails>();
MailingDetails details = new MailingDetails();
details.setMailingList(internalMailingList.get(Client.DL_NAME));
details.setTemplateSubject("someTemplate");
details.setTemplateBody("someTemplate");
internalMailingDetails.put(Client.DL_NAME, details);
return internalMailingDetails;
}
現在的郵件模板是所有環境一樣的,所以我的避風港沒有把它放在標有特定配置文件的配置中。
我試圖初始化配置文件都通過初始化ApplicationContextInitializer<ConfigurableApplicationContext>
類:
@Override
public void initialize(ConfigurableApplicationContext applicationContext) {
applicationContext.getEnvironment().setActiveProfiles("dev");
}
並把它作爲一個上下文參數:
<context-param>
<param-name>spring.profiles.active</param-name>
<param-value>dev</param-value>
</context-param>
他們都不似乎工作,雖然。它一直拋出一個bean未發現的異常。
org.springframework.beans.factory.BeanCreationException:無法自動裝配領域:私人java.util.Map com.fmr.bpo.asyncprocessingframework.invocator.wiring.configuration.pojo.common.RootConfig.internalMailingList
感謝您的幫助。