I have created a Tomcat 7 scaling app on openshift (using 2 small gears) which includes a Mysql cartridge and I have a WAR file that I deployed to it using git.
In order to handle Database transactions, I always implemented a ServletContextListener which annotates a datasource object like this:
@Resource(name="jdbc/MySQLDS")
private Datasource datasource;
then on the contextInitialized method:
public void contextInitialized(ServletContextEvent e)
ServletContext context=e.getServletContext();
context.setAttribute("ds",datasource);
which is then used by an Object I call DBHandler than manages all database transactions. This has worked fine with a single gear so far(without scaling) and I did not even need to change anything on the annotation because by default if you include a mysql cartridge, there will always be a resource called "jdbc/MySQLDS" in the .openshift/context.xml file in the git repo.
On the logs of the scaling app I detected this:
org.apache.catalina.core.StandardContext startInternal
SEVERE:Error listenerStart
SEVERE:Context [/MyApp] startup failed due to previous errors
How can I make this work on a scaling app and not have the Servlet Context failing?