Reputation: 31090
I have a "applicationContext.xml" file which has the following lines :
<bean id="jdbcPropertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<value>/WEB-INF/properties/support-center.properties</value>
</property>
</bean>
The app started fine. But when I called :
ApplicationContext ctx=new ClassPathXmlApplicationContext("applicationContext.xml");
It gave an error message :
Caused by: java.io.FileNotFoundException: class path resource [WEB-INF/properties/support-center.properties] cannot be opened because it does not exist
So, I thought maybe if I change it to <value>support-center.properties</value>
and put the property file in the same dir as applicationContext.xml , it might find it, but no, the whole app won't even start, and said it can't find support-center.properties
Now I'm confused, because the original setting : /WEB-INF/properties/support-center.properties was correct, it started the app with this setting, but why when I called :
ctx=new ClassPathXmlApplicationContext("applicationContext.xml");
it couldn't find the property ? Same setting, found at start up, but now later. Why ?
Edit :
Thanks to the answer, it worked [ with minor correction ], it should be :
<bean id="jdbcPropertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value ="classpath:support-center.properties" />
</bean>
Upvotes: 0
Views: 84
Reputation: 11304
The problem is that when new ClassPathXmlApplicationContext("applicationContext.xml")
is called, it will keep use the current path (classpath) as the location.
So /WEB-INF/properties/support-center.properties is not existing under classpath folder.
You can eith add /WEB-INF/properties/support-center.properties
to classpath or just copy the file to the same location as applicationContext.xml, then use:
classpath:support-center.properties
Upvotes: 1
Reputation: 44854
Assuming that support-center.properties is in the same directory, or in you classpath try using
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value ="classpath:support-center.properties" />
</bean>
Upvotes: 1