Java 删除PropertySourcePlaceHolderConfigurerBean自动连线不会';行不通

Java 删除PropertySourcePlaceHolderConfigurerBean自动连线不会';行不通,java,spring,Java,Spring,在spring中将“PropertySourcesPlaceholderConfigurer”添加为bean的目的是什么。据我所知,当您将属性文件命名为application.properties时,当文件位于src/main/resources文件夹中时,spring将自动获取该文件。因此,当我删除PropertySourcesPlaceholderConfigurer的Bean声明时,它说无法自动连接属性 我缺少什么,为什么没有PropertySourcePlaceHolderConfigu

在spring中将“PropertySourcesPlaceholderConfigurer”添加为bean的目的是什么。据我所知,当您将属性文件命名为application.properties时,当文件位于src/main/resources文件夹中时,spring将自动获取该文件。因此,当我删除PropertySourcesPlaceholderConfigurer的Bean声明时,它说无法自动连接属性

我缺少什么,为什么没有PropertySourcePlaceHolderConfigurer它就不能工作

样本1:

@Configuration
@PropertySource(value = { "application.properties" }, ignoreResourceNotFound = true)
@ComponentScan(basePackages = { Some Package })
public class ApplicationConfig {

    ApplicationConfig() {

    }

    @Bean
    public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
        return new PropertySourcesPlaceholderConfigurer();
    }

}
示例1运行良好,当我删除
@PropertySources
@propertysourcesplaceconfigurer
bean时,因为spring将自动拾取
应用程序。properties
不起作用

当您将属性文件命名为application.properties时, spring将在文件处于状态时自动获取该文件 src/main/resources文件夹

据我所知,这仅适用于弹簧靴。 对于SpringCore,您应该在contxet中定义PRP。 有几种方法。 在xml中


自Spring 4.3RC2以来,无需定义
属性资源占位符配置器
,如何删除
属性资源占位符配置器
?Spring将自动初始化该bean,如果它存在于classpath中,则在使用@PropertySource注释后删除手动添加的PropertySourcePlaceHolderConfigureReven的bean,而不使用PropertySourcePlaceHolderConfigurer的bean。它不起作用是的,我忘记了
@Configuration
。尝试添加它。看起来这是一个bug,将在spring版本4.3RC2Correct中修复!在pom.xml中更改spring版本成功了!Thanks@ChinniahAnnamalai没问题。我想他在我的回答中添加了关于版本的信息
< context:property-placeholder location="classpath:application.properties" />
@Configuration
@PropertySource("classpath:application.properties")