为什么在Bean A中插入参数会破坏属性解析Bean B? (两种类型均为PropertyPlaceholderConfigurer)

时间:2018-11-27 15:57:02

标签: java spring spring-boot spring-bean property-placeholder

我的项目中有两个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的唯一方法是使用参数注入来注入它。 (请参阅Why is an @Autowired field within a @Configuration class null?

我的问题是为什么将@Bean(Bean B)方法注入一个bean导致Bean A失败?

0 个答案:

没有答案