This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Tomcat and the fly likes MBean InitialContext() Tomcat query- what is the relation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "MBean InitialContext() Tomcat query- what is the relation" Watch "MBean InitialContext() Tomcat query- what is the relation" New topic
Author

MBean InitialContext() Tomcat query- what is the relation

Ravi Gupt
Greenhorn

Joined: Oct 16, 2007
Posts: 17
Hi,

I created and deployed an MBean in my tomcat. It uses datasource to connect to DB.
My questions is:

When I create InitialContext() inside MBean's constructor and pass the envContext to DBManager class to lookup datasource it works fine. However when I create InitialContext() in DBManager class, it fails.

Is it necessary to create InitialContext() during loading of MBean (either in ContextListener class or inside MBean constructor).

When I did new InitialContext() in my DBManager class which is called from hello method of MBean it failed with below exception:

avax.naming.NoInitialContextException: Cannot instantiate class: org.apache.naming.java.javaURLContextFactory [Root exception is java.lang.ClassNotFoundException: org.apache.naming.java.javaURLContextFactory]

I invoked hello method of MBean from JConsole.


Please let me know is it Tomcat specific? or same behavior is seen across all app servers. Also, What difference does it make if I create InitialContext inside MBean's constructor or in some other class at a later point of time.

Thanks
Ravi
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15960
    
  19

MBeans are not intended to contain application logic, so I'm not surprised that their classpath doesn't include all the resource you want.

MBeans are expected to be paired with actual functional beans, and that is where things like database logic and JNDI referencing should be happening.

MBeans are the interface for monitoring and control of the functional beans.

BTW, HOW did you manage to create 4 copies of your question in under 2 minutes? Is there a bug in out software?


Customer surveys are for companies who didn't pay proper attention to begin with.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: MBean InitialContext() Tomcat query- what is the relation
 
Similar Threads
How to reference a JMX MBean ?
How to get Intialcontext in a Java Class Outside container?
MBean InitialContext() Tomcat query- what is the relation