tags:

views:

65

answers:

3

Hi all, I'm building my project with maven so according to maven way, config should be in src/main/conf , how can I say to my spring application context that that is where jdbc.properties is found? Here is example bean :

<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="jdbc.properties" />
</bean>

Spring assumens that this configuration is inside src/main/webapp/WEB-INF, I hope I've been clear if not I'll rephrase my question thank you

+1  A: 

Try this

<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="src/main/config/jdbc.properties" />
</bean>
c0mrade
This only works if the final, built project puts jdbc.properties under `src/main/config` (which would be unlikely and irregular)
matt b
@matt b what about this article? http://www.javaworld.com/javaworld/jw-12-2005/jw-1205-maven.html?page=1
c0mrade
This doesn't work ..
Gandalf StormCrow
@c0mrade, what about that article? You are correct that the stated convention is for "configuration files" to go in src/main/config. What I am referring to is the fact that when you package the application, the config files are *not* packaged in a folder named `src/main/config` in the packaged file (jar/war/etc.). Therefore your answer only works when you run the application within the source code, or when `src/main/config` is in the classpath (which it is not by default). The correct prefix is to use `classpath:` or another location.
matt b
Also if you want to refer people to what the convention is, better to refer to http://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html than a javaworld article from 2005.
matt b
@matt b you're right abou that but maven guide also says `src/main/config Configuration files`
c0mrade
I don't think you're understanding why this won't work. When you run the application, src/main/config does not exist (unless you've set up special packaging with something like the appassembler plugin).
matt b
@matt b I apologize :D I didn't see the date, and yes I checked the war contains only properties in resources .. not in config
c0mrade
+1  A: 

I'm building my project with maven so according to maven way, config should be in src/main/conf

Actually, configuration data should generally go in src/main/resources, that way it will be on the classpath and you can reference your property file like:

<property name="location" value="classpath:jdbc.properties" />
Kevin
@Kevin actually configuration should be in src/main/config and resources should be in src/main/resources http://www.javaworld.com/javaworld/jw-12-2005/jw-1205-maven.html?page=1
c0mrade
@c0mrade arguably configuration files like these are "resources"
matt b
@matt b yes arguably, you say it should go to resources I think it should go into config, after all resources are probably already full of something
c0mrade
This doesn't work as well .. not if I even put the properties file in src/main/resources ..
Gandalf StormCrow
Kevin's answer is exactly what my set-up is for multiple projects. I have a runtime.properties file in src/main/resources and a propertyConfigurer bean. The only difference is that mine uses the 'locations' property:<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="locations"> <list> <value>classpath:runtime.properties</value> </list> </property> </bean>
elduff
+1  A: 

I think it is not quite clear as to what a "config file" means. I am thinking it is the config files used by the other maven plugins (such as surefire plugins, assembly plugins etc).

Surely in the 10+ web app projects that I have worked the bean files, jdbc.properties files have all been under src/main/resources

Calm Storm