将spring上下文从xml重写为java

将spring上下文从xml重写为java,java,spring-boot,Java,Spring Boot,我正在将我的Spring上下文从XML重写为Java类,但下面这个bean我不知道。有人能帮我吗?我用的是弹簧靴 <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" /> &l

我正在将我的Spring上下文从XML重写为Java类,但下面这个bean我不知道。有人能帮我吗?我用的是弹簧靴

<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>

大致如下:

@Bean
@Autowired
public PropertyPlaceholderConfigurer properties(Properties externalProperties) {
    PropertyPlaceholderConfigurer propertiesBean = new PropertyPlaceholderConfigurer();
    propertiesBean.setIgnoreUnresolvablePlaceholders(true);
    propertiesBean.setSystemPropertiesModeName("SYSTEM_PROPERTIES_MODE_OVERRIDE");
    propertiesBean.setOrder("10");
    propertiesBean.setProperties(externalProperties);
    return propertiesBean;
}
按照这些思路:

@Bean
@Autowired
public PropertyPlaceholderConfigurer properties(Properties externalProperties) {
    PropertyPlaceholderConfigurer propertiesBean = new PropertyPlaceholderConfigurer();
    propertiesBean.setIgnoreUnresolvablePlaceholders(true);
    propertiesBean.setSystemPropertiesModeName("SYSTEM_PROPERTIES_MODE_OVERRIDE");
    propertiesBean.setOrder("10");
    propertiesBean.setProperties(externalProperties);
    return propertiesBean;
}
按照这些思路:

@Bean
@Autowired
public PropertyPlaceholderConfigurer properties(Properties externalProperties) {
    PropertyPlaceholderConfigurer propertiesBean = new PropertyPlaceholderConfigurer();
    propertiesBean.setIgnoreUnresolvablePlaceholders(true);
    propertiesBean.setSystemPropertiesModeName("SYSTEM_PROPERTIES_MODE_OVERRIDE");
    propertiesBean.setOrder("10");
    propertiesBean.setProperties(externalProperties);
    return propertiesBean;
}
按照这些思路:

@Bean
@Autowired
public PropertyPlaceholderConfigurer properties(Properties externalProperties) {
    PropertyPlaceholderConfigurer propertiesBean = new PropertyPlaceholderConfigurer();
    propertiesBean.setIgnoreUnresolvablePlaceholders(true);
    propertiesBean.setSystemPropertiesModeName("SYSTEM_PROPERTIES_MODE_OVERRIDE");
    propertiesBean.setOrder("10");
    propertiesBean.setProperties(externalProperties);
    return propertiesBean;
}
试试这个:

@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;
    }

}
试试这个:

@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;
    }

}
试试这个:

@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;
    }

}
试试这个:

@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;
    }

}

对于较新版本的Spring,建议使用
PropertySourcesPlaceholderConfigurer
而不是
PropertyPlaceholderConfigurer
。定义
BeanFactoryPostProcessor
时,应将其注册为中提到的
公共静态
@Bean
方法

要加载属性,请添加一个指向属性文件位置的
@PropertySource

@Configuration
@PropertySource("path/to/your/config.properties")
public class Config {

    @Bean
    public static PropertySourcePlaceholderConfigurer configurer(){
        PropertySourcePlaceholderConfigurer configurer = new PropertySourcePlaceholderConfigurer();            
        configurer.setOrder(10);
        configurer.setIgnoreUnresolvablePlaceholders(true);         
        return configurer;
    }   
}

对于较新版本的Spring,建议使用
PropertySourcesPlaceholderConfigurer
而不是
PropertyPlaceholderConfigurer
。定义
BeanFactoryPostProcessor
时,应将其注册为中提到的
公共静态
@Bean
方法

要加载属性,请添加一个指向属性文件位置的
@PropertySource

@Configuration
@PropertySource("path/to/your/config.properties")
public class Config {

    @Bean
    public static PropertySourcePlaceholderConfigurer configurer(){
        PropertySourcePlaceholderConfigurer configurer = new PropertySourcePlaceholderConfigurer();            
        configurer.setOrder(10);
        configurer.setIgnoreUnresolvablePlaceholders(true);         
        return configurer;
    }   
}

对于较新版本的Spring,建议使用
PropertySourcesPlaceholderConfigurer
而不是
PropertyPlaceholderConfigurer
。定义
BeanFactoryPostProcessor
时,应将其注册为中提到的
公共静态
@Bean
方法

要加载属性,请添加一个指向属性文件位置的
@PropertySource

@Configuration
@PropertySource("path/to/your/config.properties")
public class Config {

    @Bean
    public static PropertySourcePlaceholderConfigurer configurer(){
        PropertySourcePlaceholderConfigurer configurer = new PropertySourcePlaceholderConfigurer();            
        configurer.setOrder(10);
        configurer.setIgnoreUnresolvablePlaceholders(true);         
        return configurer;
    }   
}

对于较新版本的Spring,建议使用
PropertySourcesPlaceholderConfigurer
而不是
PropertyPlaceholderConfigurer
。定义
BeanFactoryPostProcessor
时,应将其注册为中提到的
公共静态
@Bean
方法

要加载属性,请添加一个指向属性文件位置的
@PropertySource

@Configuration
@PropertySource("path/to/your/config.properties")
public class Config {

    @Bean
    public static PropertySourcePlaceholderConfigurer configurer(){
        PropertySourcePlaceholderConfigurer configurer = new PropertySourcePlaceholderConfigurer();            
        configurer.setOrder(10);
        configurer.setIgnoreUnresolvablePlaceholders(true);         
        return configurer;
    }   
}
是的-这个:)我最初把bean上的属性误认为是属性的一部分。当我编辑我的答案时,这个答案突然出现了。是的-这个:)我最初把bean上的属性误认为是属性的一部分。当我编辑我的答案时,这个答案突然出现了。是的-这个:)我最初把bean上的属性误认为是属性的一部分。当我编辑我的答案时,这个答案突然出现了。是的-这个:)我最初把bean上的属性误认为是属性的一部分。当我编辑我的答案时,这个答案突然出现了。