I'm trying to implement connection pooling for a Struts2 application using Tomcat 7.041. Here I'm presenting the two main files of the application which are causing the error.
The connection pooling is implemented in the server.xml I add the <Context> tag below the <Host> (line 44 below of server.xml). Then there is a listener class called AppListener. When trying to run the application I get the following error. I'd really appreciate some advice on where I'm going wrong. Please let me know if I needto provide further information and thanks in advance!
SEVERE: Exception sending context initialized event to listener instance of class app11a.listener.AppListener
java.lang.RuntimeException at app11a.listener.AppListener.contextInitialized(AppListener.java:21)
You should NOT insert a Context element into the server.xml file this way. That sort of behavior has been strongly discouraged by the Tomcat people since at least Tomcat 4. Contexts defined within server.xml hold the entire Tomcat system hostage in ways that externally-supplied Contexts do not.
Put your Context into a file named TOMCAT_HOME/conf/Catalina/localhost/app11a.xml instead.
Your stack trace looks incomplete. I would expect to have seen one or more "Caused By" sub-traces below the main traceback. As it is, the message is so vague I can't even guess.
One thing I do wonder about is the way you defined your connection pool. I haven't seen one done in that form for a long time now. Mine look more like this:
Note that it is not recommended for user "root" to be the database user ID for applications (in fact, the PostgreSQL DBMS flatly forbids it). Good practice is that you construct an alternative userid/password combination and grant the necessary rights to that user. Using the root user too freely is a security risk.
Customer surveys are for companies who didn't pay proper attention to begin with.
Thanks a lot for your response. In hindsight I started reading a lot about what a bad idea it was to put Context in server.xml. This came from a book recommendation which also includes definotion of the connection pool. Can I put my context in a context.xml file instead?
On the userid for the database, my current system is in test mode. I will of course change both userid and pw
Your book is probably antique. One of the primary reasons why you should put Context definitions in their own files is that if you change server.xml you have to restart Tomcat. Changing a context file only restarts the web application that goes with that Context.
Your connection pool definition is very likely antique as well. As I said, I haven't seen one like that in a long time.
Context files can be located in the conf/Catalina/localhost directory or inside the WAR itself as a file named META-INF/context.xml. If no context was explicitly defined Tomcat would synthesize one. But it wouldn't have a Connection Pool definition, which is why you need a Context file (in strict JEE terms, this file is known as the server-specific Deployment Descriptor, and WEB-INF/web.xml is the server-independent Deployment Descriptor).
The Tomcat documentation does a fairly good job of describing Context elements and the rules that they operate under, and a very good job of documenting the creation and care of connection pools. Tomcat 7 added a new pooling mechanism, so it's best to read the Tomcat 7 docs on it.
The book is Struts2 Design & Programming by Budi Karniawan - Second Edition. Doesn't say when it was published. First Edition was 2008. I'd agree it's fairly antique. I'll read the Tomcat documentation and adjust my files according to what I learn from those. Thanks again!
subject: Connection Pooling Error in Tomcat 7 server.xml