javax.naming.NameNotFoundException:名称"用户的数据库名称"在此上下文中不受约束?

时间:2017-09-06 16:53:09

标签: java jndi

我正在处理有以下错误的项目。我推荐互联网。跟着他们说的话。但它仍然给出了错误。这浪费了我的一整天。请建议我。

server.xml中:

<GlobalNamingResources>
    <Context docBase="targetapp" path="/targetapp" reloadable="true"/>
    <Resource auth="Container" description="User database that can be updated and saved" factory="org.apache.catalina.users.MemoryUserDatabaseFactory" name="UserDatabase" pathname="conf/tomcat-users.xml" type="org.apache.catalina.UserDatabase"/>
   <Resource driverClassName="com.mysql.jdbc.Driver" maxActive="1" maxIdle="30" maxWait="10" name="jdbc/test" password="root" type="javax.sql.DataSource" url="jdbc:mysql://localhost:3306/test" username="root"/>
  </GlobalNamingResources>

错误日志:

  

javax.naming.NameNotFoundException:名称测试未绑定在此中   上下文   org.apache.naming.NamingContext.lookup(NamingContext.java:770)at   org.apache.naming.NamingContext.lookup(NamingContext.java:140)at   org.apache.naming.NamingContext.lookup(NamingContext.java:781)at   org.apache.naming.NamingContext.lookup(NamingContext.java:153)at   com.cubs.util.DbUtil.getDataSource(DbUtil.java:61)at   com.cubs.util.DbUtil.getConnection(DbUtil.java:37)at   com.cubs.cubscore.UsersDb.getDepartmentId(UsersDb.java:3803)at at   com.cubs.cubscore.UsersDb.getMedicalDeptId(UsersDb.java:3823)at at   com.cubs.cubscore.Users.getMedicalDepartmentId(Users.java:1423)at   com.cubs.cubscore.Users.getAllMedicalAdministrators(Users.java:1447)     在org.apache.jsp.dashboard_jsp._jspService(dashboard_jsp.java:82)     在org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)     在javax.servlet.http.HttpServlet.service(HttpServlet.java:717)at   org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:386)     在   org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)     在org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)     在javax.servlet.http.HttpServlet.service(HttpServlet.java:717)at   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)     在   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)     在   org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)     在   org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)     在   org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)     在   org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)     在   org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)     在   org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)     在   org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)     在   org.apache.coyote.http11.Http11Protocol $ Http11ConnectionHandler.process(Http11Protocol.java:588)     在   org.apache.tomcat.util.net.JIoEndpoint $ Worker.run(JIoEndpoint.java:489)     在java.lang.Thread.run(Thread.java:748)06 Sep 2017 22:14:30致命   DbUtil - javax.naming.NameNotFoundException:名称nascocrm不是   在此Context中绑定java.lang.NullPointerException

1 个答案:

答案 0 :(得分:0)

我添加了这个文件META-INF文件夹然后错误不会再回来。

context.xml中:

<?xml version="1.0" encoding="UTF-8"?>
<Context path="/myapp" docBase="myapp"
   crossContext="true" reloadable="true" debug="1">
          <Resource driverClassName="com.mysql.jdbc.Driver" 
          maxActive="100" maxIdle="30" maxWait="10000" 
          name="jdbc/test" 
          type="javax.sql.DataSource" 
          url="jdbc:mysql://localhost:3306/test" username="root" password="root" />

</Context>