문제

In my Maven project , I have a spring config file. It refers to a set of properties files. Property files are available under a config folder in src/main/resources. Spring config files are available under src/main/resources/META-INF/spring/. During installation, all these files are available under target/classes as per Maven standards.

Now in spring config XML : if I refer to properties files as below its not working

property name="location" value="classpath:test.properties" or
property name="location" value="classpath*:test.properties"

I am forced to provide the subfolder to actually refer to the necessary properties file. Something like this.

property name="location" value="classpath:config/test.properties"

Is this how Maven expects us to look for properties file? Please clarify and let me know what is the best way to do this.

Thanks

도움이 되었습니까?

해결책 2

Its working now!!! I have to explicitly mention the subfolder as a new resource folder. By default maven classpath will point to src/main/resources. If we want to have a property files and XML files in specific sub folder, it should be mentioned explicitly in the pom.xml as a separate "build" tag as follows.

    <resource>
        <directory>src/main/resources/config</directory>
        <includes>
          <include>*.xml</include>
          <include>*.properties</include>
        </includes>            
    </resource>

다른 팁

In Spring classpath refers to the classes folder. If your configuration files are under a subfolder of classes, config in your case, you need to specify the sub folder name. Therefore, that's why the following works:

property name="location" value="classpath:config/test.properties"

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top