I build an application which has a standalone "core" layer, that is also used to build a webapp (it is a Maven multi-module project, with a 'core' module, and a 'webapp' module, that has a dependency to the 'core' module).
It uses a MySQL database. I try to implement a DataSource
that would be fine in both contexts (only 1 connection is enough in the standalone context).
After reading a lot of documentations about DataSources, I have to say that I am a bit lost. I came to the conclusion that maybe I should use the Tomcat JDBC Connection Pool. My questions are:
1) in the standalone context, how should I provide the configuration to use the DataSource, knowing that this configuration will be provided by Tomcat in the webapp context (the standalone config should thus not override the Tomcat config)?
Should I do something like in this other question in a method called only in the standalone context? But how can I see in the webapp context that Tomcat has already provided the DataSource?
Or Should I rather use a bean definition? But how this bean would not be used in the webapp context?
2) What about other pooled DataSource implementations?
Shouldn't I just use the MySQL DataSource?
I read that in Java EE 7, DataSources are simpler to use (https://blogs.oracle.com/arungupta/entry/default_datasource_in_java_ee). So, is there any breakthrough in Java 7? A new DataSource provider that I should absolutely use in Java 7?
Conclusion: Yep, I'm lost, and I don't know what are the "gold standards" for DataSource usage. Thank you for your help.