Java, Spring, Unable to find /WEB-INF/spring.properties do I need to set it somewhere besides propertyConfigurer?
I am getting an error message that Could not load properties; nested exception is java.io.FileNotFoundException: class path resource [WEB-INF/spring.properties] cannot be opened because it does not exist
. The spri开发者_Go百科ng.properties files does exist and is in my /WEB-INF directory (I have confirmed that it is in my build directory after building the project). I have it set on my project's .classpath directory like this:
<classpathentry kind="src" path="src/main/webapp/WEB-INF/spring.properties"/>
In my Spring application context, I have it entered like this:
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="/WEB-INF/spring.properties" />
</bean>
I apologize if this is a basic question but I really am perplexed as to what the problem is and how to solve it, I have done a lot of searching on this and can't seem to figure it out. Thanks for any advice
Looking at one of my webapps that uses a PropertyPlaceholderConfigurer
, I see that I put the properties in /WEB-INF/classes
and then configured the PPC to use it with a Spring classpath:
URL; i.e.
/WEB-INF/classes/substitution.properties
accessed as
classpath:substitution.properties
Spring supports a ServletContextResource, which you can use by leaving off the resource prefix entirely. "You will get back a Resource type that is appropriate to that particular application context", and since we are using a web context, that resource will be a ServletContextResource.
The path is from the root of your webapp. Our paths look like
<context:property-placeholder location="/WEB-INF/spring/appServlet/application.properties"/>
Your path ("src/main/webapp") suggests you are using Maven to build the project. If this is the case, put your .properties -file(s) to /src/main/resources and use "classpath:<filename>
" to access them, everything under src/main/resources should be accessible through classpath without any further configuration.
Try putting the file under WEB-INF/classes/
and referring to it with value="spring.properties"
. I think that should do the trick.
Just put the spring.properties file under the directory src/main/webapp (alongside WEB-INF) and referring to it with
<bean id="placeholderConfig"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>spring.properties</value>
</list>
</property>
</bean>
精彩评论