我的项目中有两个 PropertyPlaceholderConfigurer bean。
Bean A:(定义为 XML)
<bean id="propertyConfigurer" class="org.jasypt.spring3.properties.EncryptablePropertyPlaceholderConfigurer">
<constructor-arg ref="configurationEncryptor" />
<property name="order" value="0" />
<property name="locations">
<list>
<value>classpath:/app-dev.properties</value>
<value>classpath:/common-dev.properties</value>
</list>
</property>
</bean>
Bean B:(定义为 Java Config)
@Bean(name = "customPropertiesUtil")
public static CustomPropertiesUtil customPropertiesUtil(StandardPBEStringEncryptor configurationEncryptor) {
CustomPropertiesUtil customPropertiesUtil = new CustomPropertiesUtil ();
customPropertiesUtil.setSystemPropertiesModeName("SYSTEM_PROPERTIES_MODE_OVERRIDE");
customPropertiesUtil.setLocation(new ClassPathResource("mail-dev.properties"));
customPropertiesUtil.setOrder(1);
customPropertiesUtil.setIgnoreUnresolvablePlaceholders(false);
customPropertiesUtil.setStandardPBEStringEncryptor(configurationEncryptor);
return customPropertiesUtil;
}
bean configurationEncryptor 在 XML 中定义为:
<bean id="configurationEncryptor" class="org.jasypt.encryption.pbe.StandardPBEStringEncryptor">
<property name="config" ref="environmentVariablesConfiguration" />
</bean>
Bean B 在 @Configuration 类中创建。奇怪的是,如果我删除 Bean B 中显示的参数注入,一切都会按预期工作。但是,我需要加密器来解析一些加密属性,并且它不是 NULL 的唯一方法是使用参数注入来注入它。(请参阅为什么 @Configuration 类中的 @Autowired 字段为空?)
我的问题是,将 bean 注入 @Bean (Bean B) 方法会导致 Bean A 失败?