On 20/12/2011 11:57, S B wrote: > MBeanImpl code is packaged as a war and deployed in tomcat along with it's > mbeans-descriptor.xml > I am not using ServletContextListener in my code. (mbean registration is > done inside constructor).
Right, but what is calling the constructor? > (I am using gmail and hitting reply button on your messages. Please let me > know if my messages are not being put in order as mailing list expects.) That shouldn't prevent you from scrolling down and entering your replies at the appropriate points in the text. Just like I am. p > On Tue, Dec 20, 2011 at 5:18 PM, Pid <p...@pidster.com> wrote: > >> On 20/12/2011 11:46, S B wrote: >>> Code Sample that fails with exception(I am invoking reload() from >> jconsole >>> ): >>> >>> class MBeanImpl implements MBeanInterface{ >>> >>> public MBeanImpl{ >>> // code to register this bean. >>> } >>> >>> >>> @Override >>> public void reload() { >>> >>> DBManager.loadFromDB(); >>> >>> } >>> } >>> >>> >>> class DBManager{ >>> >>> public static void loadFromDB(){ >>> >>> InitialContext initContext = new >>> InitialContext(); // here it fails with exception >>> avax.naming.NoInitialContextException: Cannot instantiate class: >>> org.apache.naming.java.javaURLContextFactory [Root >>> >>> // exception is java.lang.ClassNotFoundException: >>> org.apache.naming.java.javaURLContextFactory] >>> Context context = (Context) >>> initContext.lookup("java:comp/env"); >>> logger.info("context found " + context); >>> BasicDataSource ds = (BasicDataSource) >>> context.lookup("jdbc/" + dataSourceName); >>> ............... >>> ............... >>> } >>> >>> } >>> >>> >>> --------------------------------------------- >>> >>> Code Sample that works: >>> >>> class MBeanImpl implements MBeanInterface{ >>> private Context envContext = null; >>> >>> public MBeanImpl{ >>> InitialContext initialContext = new InitialContext(); >>> envContext = (Context) >> initialContext.lookup("java:/comp/env"); >>> // code to register this bean. >>> } >>> >>> >>> @Override >>> public void reload() { >>> >>> DBManager.loadFromDB(envContext); // passed context object >>> obtained in constructor >>> >>> } >>> } >>> >>> >>> class DBManager{ >>> >>> public static void loadFromDB(Context context){ >>> >>> BasicDataSource ds = (BasicDataSource) >>> context.lookup("jdbc/" + dataSourceName); // works fine as I am not >>> creating new InitialContext here. >>> ............... >>> ............... >>> } >>> >>> } >> >> Where does the MBeanImpl code run? In a ServletContextListener, or >> somewhere else? >> >> >> p >> >> >>> On Tue, Dec 20, 2011 at 4:59 PM, S B <sbl...@gmail.com> wrote: >>> >>>> Hi, >>>> I am using : >>>> >>>> Server version: Apache Tomcat/6.0.32 >>>> OS Name: Mac OS X >>>> OS Version: 10.6.8 >>>> Architecture: x86_64 >>>> JVM Version: 1.6.0_29-b11-402-10M3527 >>>> >>>> Thanks, >>>> Ravi >>>> >>>> >>>> On Tue, Dec 20, 2011 at 4:52 PM, Pid * <p...@pidster.com> wrote: >>>> >>>>> On 20 Dec 2011, at 11:02, S B <sbl...@gmail.com> wrote: >>>>> >>>>>> Hi, >>>>>> >>>>>> I created and deployed an MBean in my tomcat. It uses datasource to >>>>> connect >>>>>> to DB. >>>>> >>>>> Which version of Java? Tomcat? >>>>> >>>>> >>>>>> 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). >>>>> >>>>> It depends on where you run the code. You haven't told us this. >>>>> >>>>> Can you post a code example. >>>>> >>>>> >>>>> p >>>>> >>>>> >>>>>> 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 >>>>> >>>>> --------------------------------------------------------------------- >>>>> To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org >>>>> For additional commands, e-mail: users-h...@tomcat.apache.org >>>>> >>>>> >>>> >>> >> >> >> -- >> >> [key:62590808] >> >> > -- [key:62590808]
signature.asc
Description: OpenPGP digital signature