Apr 9th, 2009, 08:10 AM
Changing dataSource based on server environment in jboss
I have jdbc beans accessing a db based on a dataSource defined in and injected by a bean. The dataSource is defined in /WEB-INF/app-db-context.xml. When the war is deployed on the dev server, the jdbc url points to dev-db, but when the ear is pushed to production server, it should point to prod-db, but there is no recompile to reassemble a war with a different /WEB-INF/app-db-context.xml so I need to have a config file of some description sitting on each server that always points to the corresponding db.
We are deploying to jboss, and there is a server /lib/ directory. Should I just have the web.xml file load context files from /WEB-INF/ for beans that are the same on all environments, but also have it load a classpath:/app-db-context.xml and let it pick up the local servers /lib/app-db-context.xml?
Not even sure that would work. Anyone aware of a "best practice" for this?
Apr 9th, 2009, 09:15 AM
So I have in the /WEB-INF/ctx.xml specified that the jdbc url/pw/user to be obtained from a properties file outside of the deployment war. But I can only get the database.properties file to be found if it is specified with an absolute path using file://C:/path/to/file/database.properties.
The jboss server uses the server/default/lib directory as a classpath, but if I specify the classpath:database.properties as the prop file to use, the dataSource bean in the ctx.xml cannot see it. Only if I use the file:// specification.
Is the class path used for the "classpath:database.properties" limited to INSIDE the war? Any thoughts on using a more "relative" location for the database.properties file OUTSIDE the war? (jboss 4.0.4/ Cocoon 2.1.8 is loading the ctx).