2

I am unable to load a file path into my application. Can any one please help me out.

Here is the spring xml config :

<context:property-placeholder location="file:${globalproplocation}"
        ignore-unresolvable="true" ignore-resource-not-found="true" order="-1" />

I have added this to JAVA_OPTS under catalina.sh as shown below:

JAVA_OPTS="-XX:MaxPermSize=4096m  -XX:PermSize=1024m -Dglobalproplocation=/Users/admin/properties/temp.properties"

But some how it is not being picked up, here is my tomcat log.

    <Loading properties file from ServletContext resource [/${globalproplocation}]>
    2016-05-07 02:52:24,089 WARN [org.springframework.beans.factory.config.PropertyPlaceholderConfigurer] -
<Could not load properties from ServletContext resource [/${globalproplocation}]: 
Could not open ServletContext resource [/${globalproplocation}]>

What am I doing wrong here?

Siddarth
  • 1,000
  • 1
  • 10
  • 17

2 Answers2

0

The problem hear is that when Spring Context start and see in you configuration file a place holder ${globalproplocation}, and it try to load a file path like this: ${globalproplocation}. The problem hear is that when you pass the paramiter like -Dglobalproplocation=/Users/admin/properties/temp.properties the xml don't will be modified and the context contiuos to try loading an inisistent file. For overcome this issue you can use maven and the resource processiong plug-in with a configuration like below.

<build>
    <properties>
            <globalproplocation>/Users/admin/properties/temp.properties</globalproplocation>
    </properties>
    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
        </resource>
    </resources>

    <plugins>
        <!-- Facilitates downloading source and javadoc in Eclipse -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-resources-plugin</artifactId>
            <version>2.3</version>
            <configuration>
                <!-- specify UTF-8, ISO-8859-1 or any other file encoding -->
                <encoding>UTF-8</encoding>
            </configuration>
        </plugin>
    </plugins>
</build>

Then you can perform the command mvn clean package and the build result will have the xml file will be trasformed and the palceholder will be replaced whit the correct path.

I hope that this help you.

Valerio Vaudi
  • 4,199
  • 2
  • 24
  • 23
0

spring xml config :

`<bean 
    class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="propname">
        <value>test.properties</value>
    </property>
</bean>`

Alternate option use classpath

<bean name="propertyPlaceholder" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="propname"> <value>classpath:test.properties</value> </property> </bean>

Pavan
  • 1,219
  • 13
  • 15