tomcat - I am Moving my application Web-logic to Tomcat7 -


the below code working fine while application running in weblogic in tomcat giving error. main problem loading java:comp/env/jmx/runtime.

so please let me know configuration need run code in tomcat.

my code:

    mbeanserver server = (mbeanserver)ctx.lookup("java:comp/env/jmx/runtime");     // platform mbean server     objectname rs = new objectname("com.bea:name=runtimeservice,type=weblogic.management.mbeanservers.runtime.runtimeservicembean");     hashmap map = null;     try     {         objectname domcfg = (objectname) server.getattribute(rs,"domainconfiguration");          objectname[] jdbcsysresources =         (objectname[]) server.getattribute(domcfg, "jdbcsystemresources");          map = new hashmap();         (int i=0 ; i<jdbcsysresources.length ; i++)         {             objectname jdbcresourcebean = (objectname) server.getattribute(jdbcsysresources[i],"jdbcresource");              objectname driverparamsbean =(objectname)server.getattribute(jdbcresourcebean,"jdbcdriverparams");             stringbuffer jdbcparams = new stringbuffer();             objectname drvpropertiesbean = (objectname)server.getattribute(driverparamsbean,"properties");             objectname[] drvproperties = (objectname[])server.getattribute(drvpropertiesbean,"properties");              for(int j=0; j<drvproperties.length; j++)             {                 string propname = (string)server.getattribute(drvproperties[j],"name");                 string propval = (string)server.getattribute(drvproperties[j],"value");                 jdbcparams.append(propname).append("=").append(propval).append(";");             }             string strtest = drvproperties.tostring();              objectname dsnparams =(objectname)server.getattribute(jdbcresourcebean,"jdbcdatasourceparams");              string[] dsnparamnames = (string[])server.getattribute(dsnparams,"jndinames");             map.put(dsnparamnames[0].tostring(),jdbcparams.tostring()); 

error in tomcat server:-

systemcheck - naming exception: javax.naming.namenotfoundexception:  name [jmx/runtime] not bound in context. unable find [jmx]. 04/22 01:32 systemavailability -> mel check failed - null java.lang.nullpointerexception 

tomcat context.xml--- -- data source 1 --
< resource name="jdbc/datasource1" auth="container" driverclassname="com.microsoft.sqlserver.jdbc.sqlserverdriver" maxactive="50" maxidle="10" maxwait="10000" password="mel01" type="javax.sql.datasource" url="jdbc:sqlserver://xxx:1460;databasename=xxx" username="xxx" validationquery="select 1"/> -- data source 2 --
. ..

    < resource  name="jdbc/datasource2"  auth="container" driverclassname="com.microsoft.sqlserver.jdbc.sqlserverdriver" maxactive="50" maxidle="10" maxwait="10000"password="xxxx" type="javax.sql.datasource" url="jdbc:sqlserver://xxxx:1460;databasename=xxx" username="xxx" validationquery="select 1"/> 

web.xml---

  <resource-ref>     <res-ref-name>jdbc/datasouce1</res-ref-name>     <res-type>javax.sql.datasource</res-type>     <res-auth>container</res-auth> </resource-ref>  <resource-ref>     <res-ref-name>jdbc/datasouce2</res-ref-name>     <res-type>javax.sql.datasource</res-type>     <res-auth>container</res-auth> </resource-ref>  

tomcat doesn't come jndi broker, unlike weblogic. make code work is, you'd need add jndi provider.

i'd recommend using di instead.

spring framework can either (for example).

here's example


Comments