Java applicationContext未加载作为某些文件路径的属性

Java applicationContext未加载作为某些文件路径的属性,java,spring,intellij-idea,applicationcontext,Java,Spring,Intellij Idea,Applicationcontext,我在项目的META-INF文件夹中有一个应用程序上下文文件 目录树: ├── src    ├── main    │   . . . . .    └── test    ├── java . . . . .    └── resources   

我在项目的
META-INF
文件夹中有一个应用程序上下文文件

目录树:

├── src
    ├── main
    │   .
        .
        .
        .
        .

    └── test
        ├── java
            .   
            .   
            .   
            .   
            .   

        └── resources
            ├── META-INF
            │   ├── applicationContext.annotation.config.xml
            │   ├── applicationContext.annotationTestCase.config.xml
            │   └── applicationContext.xml
            │
            ├── annotation.properties
            ├── annotationTestCase.properties
            ├── query.properties
            └── project.properties
applicationContext.xml
中,我有一个属性:

<property name="propFile" value="annotation.properties"/>
我还打印了
propsFile
的值,它是
annotation.properties


可能出了什么问题?

这不是文件名,请检查您试图读取的文件路径

// From ClassLoader, all paths are "absolute" already - there's no context
// from which they could be relative. Therefore you don't need a leading slash.
   InputStream in = this.getClass().getClassLoader()
                            .getResourceAsStream("annotation.properties");
这不是很好的编码,但是使用spring代替。PropertyPlaceHolderConfigure以加载任何属性文件

<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="location">
        <value>annotation.properties</value>
    </property>
</bean>

注释.属性
如果希望名称“annotation.properties”是动态的,则从系统属性传递它


java-DpropertyFilePath=/path/to/propertyfile

路径在类路径中,而不是常规文件,我建议使用Springs资源抽象来加载文件,而不是自己加载。
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="location">
        <value>annotation.properties</value>
    </property>
</bean>