Reputation: 58063
Java-Spring I have modules based project, i have module for DAO layer and module for business layer which is dependent upon DAO layer and web layer dependent upon DAO layer and business layer.
I am using maven for project compilation. and jar of every components are group under web projects lib folder.
Problem is i have spring context file and .property file inside DAO jar and following is my configuration but i spring unable to load properties i also tried prefixing value="classpath:abc.properties
but it didn't work.
When i open the DAO jar both spring context and .properties files are on root.
<bean id="applicationProperties" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="abc.properties" />
</bean>
<bean id="cmfModelDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="${jdbc.ConnectionUrl}"/>
<property name="username" value="${jdbc.Username}"/>
<property name="password" value="${jdbc.Password}"/>
</bean>
any idea how to quick fix this issue ?
Upvotes: 6
Views: 3836
Reputation: 1898
I had that error and int might have to do with the way you are initializing the context, for example in my web app the problem was somehing with the filter I setup in the web.xml file. Also I end up using not an xml file but an Annotated Config Class and placed this in the web.xml:
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextClass</param-name>
<param-value>
org.springframework.web.context.support.AnnotationConfigWebApplicationContext
</param-value>
</context-param>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>com.myapp.configuration.SpringConfig</param-value>
</context-param>
If you really want to use an xml file you must change the AnnotationConfigWebApplicationContext for an XmlWebApplicationContext. You should tell us how are you initilizing your context (like the code or web.xml if this is does not solve your issue)
Upvotes: 0
Reputation: 835
I have a multi-module web project with Spring using the following code:
<context:property-placeholder location="classpath:env/env.properties" />
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${env.datasource.driver}" />
<property name="url" value="${env.datasource.url}" />
<property name="username" value="${env.datasource.username}" />
<property name="password" value="${env.datasource.password}" />
</bean>
Don`t forget to verify the namespace url in the xml file:
xmlns:context="http://www.springframework.org/schema/context";
The folder env must be in classpath, so Spring can find it. My properties file is also inside a jar, and it`s working just fine.
Upvotes: 1