· DO NOT configure the DataSource (or) EntityManagerFactory in the Spring beans.
· The version of Tomcat SHOULD BE minimum of 7.0.25. For lower versions of Tomcat you still need to use the regular connection like driverà url à password etc., This is a BUG with Tomcat server itself.
· If you try to use DataSource with earlier versions of the Tomcat, then you will see JNDIExceptions
· Since Tomcat does not support JTA , you need to have the following configuration for the datasource in your persistence.xml file
· For hibernate way it will be the following
· Note that for Tomcat you need to make sure that you are reading the datasource as a “resource” and that’s why you need have the java:compo/env as a prefix for the datasource.
· Now normally you configure the resources in either.
a. <Tomcat_Home>\Conf\context.xml (or)
b. <Tomcat_Home>\Conf\server.xml (or)
· But once this is done as above the whole of Tomcat applications will have access to that resource which we do not want to do. This also means that that you need to have database specific driver files loaded and visible to all the applications deployed.
· EPH proposes to use application specific Context files. Here are the steps for the same.
· Create a file called “context.xml” in your webapp folder
· The contents of this file is as follows
· Note the equality in “name” and “path” in the above file.This way your DB driver files are loaded at runtime (WEB-INF\lib) and not at server start up time.