有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java为什么Bean A中的参数注入会破坏属性解析Bean B?(都是类型PropertyPlaceHolderConfigure的类型)

我的项目中有两个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配置)

@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(bean B)方法会导致bean a失败


共 (0) 个答案