Jun 7th, 2011, 11:24 PM
how to configure spring roo to read database.configuration outside application.
Im created one module (java jar file) that handle all data model and database connection using spring roo. It works great, i can use it with desktop app and web app. My problem is by default the database.configuration is stored in the META-INF/spring folder and it read the database configuration inside the jar file. How i can configure the my module to read the database.configuration outside the jar file or read from other application.
Jun 8th, 2011, 06:29 PM
The traditional way to meet this requirement is to register your DataSource via JNDI; your application can then (in the Spring bean file) look up the datasource (and/or an associated EntityManagerFactory if using JPA) using its JNDI name, without having to know any other configuration details. See here for details:
You will have to consult your web/application server's documentation to see how to deploy a DataSource and/or an EntityManagerFactory (I know that JBoss can automatically create the latter for you if you add a particular property to persistence.xml).
Jun 9th, 2011, 06:09 AM
I will try the JNDI solution like you suggested.
Jun 9th, 2011, 04:20 PM
You can try to put your database.properties file outside the jar, in an external folder, and configuring that folder to be in the classpath: using java -classpath or java -Djava.class.path or something similar.
Since the application will try to scan the location configured in the applicationContext.xml: <contextroperty-placeholder location="classpath*:META-INF/spring/*.properties"/> you can either create this path in your external folder or modify this line for including the path inside your configured external classpath folder.
If you have a copy of this file in the test/resources, the JUnit will work both with maven and in your IDE. Alternatively you can configure the classpath tab in the run configurations within your IDE for JUnit and Java Applications.
There is a classpath tab too for the TC Server (double click it and select "Open launch configuration") for your local server testing.
Tags for this Thread