我正在将Spring上下文从XML重写为Java类,但是下面的这个bean我不知道。谁能帮我?我正在使用Spring Boot。

<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
    <property name="order" value="10"/>
    <property name="ignoreUnresolvablePlaceholders" value="true" />
    <property
              name="properties" ref="externalConfigProperties">
    </property>
</bean>

最佳答案

尝试这个:

@Configuration
public class Config {

    @Autowired Properties externalConfigProperties;

    @Bean
    PropertyPlaceholderConfigurer configurer(){
        PropertyPlaceholderConfigurer configurer = new PropertyPlaceholderConfigurer();
        configurer.setSystemPropertiesModeName("SYSTEM_PROPERTIES_MODE_OVERRIDE");
        configurer.setOrder(10);
        configurer.setIgnoreUnresolvablePlaceholders(true);
        configurer.setProperties(externalConfigProperties);
        return configurer;
    }

}

10-06 13:57