javax.naming.NameNotFoundException: 名称 "user's db name" 未在此上下文中绑定?
javax.naming.NameNotFoundException: Name "user's db name" is not bound in this Context?
我正在处理有以下错误的项目。我提到了互联网。按照他们说的去做。但它仍然给出错误。它浪费了我一整天。请给我建议。
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: Name test is not bound in this
Context at
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
com.cubs.cubscore.UsersDb.getMedicalDeptId(UsersDb.java:3823) at
com.cubs.cubscore.Users.getMedicalDepartmentId(Users.java:1423) at
com.cubs.cubscore.Users.getAllMedicalAdministrators(Users.java:1447)
at org.apache.jsp.dashboard_jsp._jspService(dashboard_jsp.java:82)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) at
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:386)
at
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
at
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:748) 06 Sep 2017 22:14:30 FATAL
DbUtil - javax.naming.NameNotFoundException: Name nascocrm is not
bound in this Context java.lang.NullPointerException
我把这个文件添加到 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>
我正在处理有以下错误的项目。我提到了互联网。按照他们说的去做。但它仍然给出错误。它浪费了我一整天。请给我建议。
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: Name test is not bound in this Context at 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 com.cubs.cubscore.UsersDb.getMedicalDeptId(UsersDb.java:3823) at com.cubs.cubscore.Users.getMedicalDepartmentId(Users.java:1423) at com.cubs.cubscore.Users.getAllMedicalAdministrators(Users.java:1447) at org.apache.jsp.dashboard_jsp._jspService(dashboard_jsp.java:82) at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:386) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260) at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489) at java.lang.Thread.run(Thread.java:748) 06 Sep 2017 22:14:30 FATAL DbUtil - javax.naming.NameNotFoundException: Name nascocrm is not bound in this Context java.lang.NullPointerException
我把这个文件添加到 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>