简体   繁体   中英

Not able to find Spring “classpath:” location

I have a Spring Project where I am using bean configuration file beans.xml .Inside the bean Configuration file, i have defined some properties for a PlaceHolder which refers to classPath...While the application is running, the properties are getting loaded from /unknownPath/Dev/Loc1/System.properties

Where

${BUS_ENV}=Dev
${LOCATION1}=Loc1

<bean id="placeholderProperties" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="locations">
        <list>
            <value>classpath:${BUS_ENV}/${LOCATION1}/system.properties</value>
            <value>classpath:${BUS_ENV}/lbsprocessor.properties</value>
        </list>
    </property>
    <!-- Force system properties to override any deployed runtime properties -->
    <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE"/>
    <property name="ignoreUnresolvablePlaceholders" value="true" />

</bean>
  1. I didn't specify classpath while running my project in IDE
  2. I don't have those files in my resource folder
  3. There are around 65 such files exists(for various reasons) as Dev/Loc1/System.properties
  4. I am not able to find from which location the properties are getting referred. Even after debugging, I couldn't find out what classpath refers to. Please help me with figuring out

If you are using eclipse IDE right click on your project select properties then select Java Build Path. On first tab Source there is one input named Default Output folder that value is your classpath. Check all your properties files are there in that path.

Referring to your point 2 problems might be in these line

<value>classpath:${BUS_ENV}/${LOCATION1}/system.properties</value>
<value>classpath:${BUS_ENV}/lbsprocessor.properties</value>

You are using classpath for file location which means these properties file have to be in the .war file at /Dev/Loc1/System.properties

If properties files are outside of project may be at system level you can access them like this

<value>file:${BUS_ENV}/${LOCATION1}/system.properties</value>
<value>file:${BUS_ENV}/lbsprocessor.properties</value>

eg:

<value>file:/home/testuser/system.properties</value>

我使用的是Mac OS,因此我们将配置存储为jar文件,存储在/ Library / Java / Extension下。因此,默认情况下,java直接将类路径引用到该位置。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM