开发者

Getting JNDI to work with RDS

I'm trying to configure Tomcat 7 to use an RDS/MySQL instance and I'm having no luck. I suspect the problem is in my context.xml. With a context.xml present, bad things happen like not being able to remote debug through Eclipse and therefore not being able to debug what is happening with my DB code. My context.xml (with details like username/password removed to protect the innocent):

<?xml version='1.0' encoding='utf-8'?>
<Context path="/puppy" reloadable="true" crossContext="true">
    <Resource name="jdbc/myDB" 
      auth="Container"
      type="javax.sql.DataSource" 
      username="username" 
      password="password"
      driverClassName="com.mysql.jdbc.Driver"
      url="jdbc:mysql://rds-instance:3306/myDB?autoReconnect=true"
      validationQuery="select 1"
      maxActive="10" 
      maxIdle="4"/>
</Context>

Upon deploying the app, I get the following in my logs:

WARNING: Failed to retrieve JNDI naming context for container [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/puppy]] so no cleanup was performed for that container
javax.naming.NameNotFoundException: Name comp is not bound in this Context
    at org.apache.naming.NamingContext.lookup(NamingContext.java:803)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:159)
    at org.apache.catalina.deploy.NamingResources.cleanUp(NamingResources.java:975)
    at org.apache.catalina.deploy.NamingResources.stopInternal(NamingResources.java:957)
    at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:225)
    at org.apache.catalina.core.StandardContext.stopInternal(StandardContext.java:5504)
    at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:225)
    at org.apache.catalina.core.StandardContext.reload(StandardContext.java:3847)
    at org.apache.catalina.manager.ManagerServlet.reload(ManagerServlet.java:949)
    at org.apache.catalina.manager.HTMLManagerServlet.reload(HTMLManagerServlet.java:676)
    at org.apache.catalina.manager.HTMLManagerServlet.doPost(HTMLManagerServlet.java:214)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.filters.CsrfPreventionFilter.doFilter(CsrfPreven开发者_运维问答tionFilter.java:187)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:572)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:563)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:403)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:301)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:162)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:309)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
    at java.lang.Thread.run(Thread.java:636)
Jul 6, 2011 4:44:52 AM org.apache.catalina.core.NamingContextListener lifecycleEvent
SEVERE: Creation of the naming context failed: javax.naming.NamingException: Context is read only

Any idea what's going on? Are people not using JNDI with RDS? What's the best approach?


it may be because of previous applications are not properly undeployed from tomcat container.

Stop the tomcat, and then go to the tomcat conf directory /<Tomcat root>/conf/Catalina/localhost and clean the xml files in that directory. and restart the tomcat

Note: 1. make a backup of those xml files before deleting, so that if this not works then you can restore it.


I had a similar issue on local trying to deploy a webapp with a jndi reference on tomcat8. It seems like newer versions of tomcat needs to link resources in server context.xml configuration. In my case i solved it adding the following line to the server context.xml:

<ResourceLink name="JDBC_DATASOURCE_NAME_DEF_IN_SERVER:XML" global="JDBC_DATASOURCE_NAME_DEF_IN_SERVER:XML" type="javax.sql.DataSource"/>

The JDBC_DATASOURCE_NAME_DEF_IN_SERVER:XML means to use the name used to define the resource in the server.xml configuration file of your tomcat instance.

The name attr- the name used to expose the resource to deployed application contexts.

The global attr.- The name of the jndi resource defined in the server.xml configuration file of tomcat.

Hopes this helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜