Brad Fritz
unread,Oct 20, 2011, 7:38:11 PM10/20/11Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to javamelody
I just spent several hours debugging a problem where my app, that
retrieves its DataSource via JNDI, was bypassing the JavaMelody
JDBC proxy despite the DataSource being rebound. Hopefully this
will save the next person a few hours...
TL;DR:
The JavaMelody SessionListener should be listed *before* any Spring
ContextLoaderListener in web.xml. Otherwise, the monitored app may
grab a DataSource before JavaMelody has a chance to rebind it with
a proxied version. Obvious in hindsight but an easy mistake to make
and painful to debug.
Here is a bit more information for the archives...
Problem:
Monitored webapp was using DataSource from JNDI to make database
calls but the "Statistics sql" section remained empty except for
calls made via the "Database page at /monitoring?part=database .
Setup:
* Apache DBCP BasicDataSource registered in JNDI via Jetty's
org.mortbay.jetty.plus.naming.Resource class.
* Application uses Spring's JndiObjectFactoryBean to lookup
DataSource and wire it into LocalSessionFactoryBean for
Hibernate.
* Spring context loaded via ContextLoaderListener listener-class
in web.xml.
* JavaMelody JDBC proxy and JNDI rebinding initialized via
SessionListener listener-class in web.xml
* SessionListener *incorrectly listed after* ContextLoaderListener.
Fix:
Declare the web.xml <listener> for SessionListener *before* Spring's
ContextLoaderListener so JavaMelody can rebind the JNDI DataSource
before Spring creates a bean with the unproxied version.
It might be worthwhile to update section 2 of the UserGuide wiki page
to emphasize the <listener> ordering. Does not look like I can do
that
myself, but I will add a comment at the bottom of the page. (Would be
really nice if JavaMelody could detect that scenario automatically and
log a warning.)
--Brad
Brad Fritz
Software Developer
Indianapolis, IN