1. javax.naming.NoInitialContextException
javax.naming.NoInitialContextException: Need to specify class name in environment or
system property, or as an applet
parameter, or in an application resource file:
java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:325)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at com.pk.jdni.TestJNDI.main(TestJNDI.java:25)
原因: 测试JNDI数据源需要在web环境下测试.不能在纯j2se环境下运行.
解决方法: 在JSP页面中测试,或者在servlet中测试均可.
2.org.apache.tomcat.dbcp.dbcp.SQLNestedException
org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class ''
for connect URL 'null' at
org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource
情景:在tomcat6.0中配置jndi数据源,并在容器中测试数据源是否配置成功时,出现如上异常.
原因: 数据源配置问题.如果数据源配置,测试代码均无问题。请在tomcat安装目录下找到
Webapp目录,删除该目录下发布的应用,同时找到work目录,并删除Catalina目录下的localhost文件夹.如此以来,
重新测试。
3.java.lang.IllegalStateException
java.lang.IllegalStateException: Web app root system property already set to different
value: 'xjgs_nws.root' =
[D:\workspace\xjgs_nws\WebRoot\] instead of
[D:\apache- tomcat-6.0.32\webapps\xjgs_nws\] - Choose unique values for
the 'webAppRootKey' context-param in your web.xml
files!
org.springframework.beans.factory.BeanCreationException: Error creating bean with
name 'dataSource' defined in ServletContext
resource [/WEB-
INF/classes/applicationContext.xml]: Invocation of init method failed; nested exception
is javax.naming.NameNotFoundException:
Name nws is not bound in this Context
Caused by: javax.naming.NameNotFoundException: Name nws is not bound in this Context
...
严重: Context [/xjgs_nws] startup failed due to previous errors
注意: 如果在server.xml 中配置数据源时,如果配置无误,但是控制台总是报错如上:
找不到jndi名字.
解决方法:在server.xml 中将context对应的信息先注释掉,然后在不加载任何资源的情况下引导tomcat启动,引导
成功之后,去掉注释,再重新加载就可以了.
从这一点来说, 在server.xml 中配置数据源不太稳定,当出现问题时,需要重新引导,然后才能加载.
出现错误的原因就是原来产生了错误. 严重: Context [/xjgs_nws] startup failed due to previous
errors