当前位置: 代码迷 >> Web前端 >> 错误备忘 - Web Project on shblog
  详细解决方案

错误备忘 - Web Project on shblog

热度:531   发布时间:2012-10-31 14:37:32.0
异常备忘 - Web Project on shblog

2009-10-10

今日调试项目shblog时,出现了No WebApplicationContext found: no ContextLoaderListener registered异常,此问题产生的原因是因他的资源文件没加载进来所以找不到文件引起.

在web.xml应该改成:
<context-param>
?????? <param-name>contextConfigLocation</param-name>
?????? <param-value>/WEB-INF/classes/applicationContext.xml</param-value>
</context-param>

2009-10-11
1.
继续昨天的调试,发现web.xml改成上面的配置后,当初始化的时候可以找到applicationContext.xml,但是立刻弹出另外的问题:
HTTP Status 500 -
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'blogdb' defined in? ServletContext resource [/WEB-INF/classes/applicationContext.xml]: Instantiation of bean failed; nested exception is? java.lang.NoClassDefFoundError: org/apache/commons/pool/impl/GenericObjectPool
它提示找不到类: org/apache/commons/pool/impl/GenericObjectPool

解决办法如下:
把 Commons-Pool jar包放到F:\Tomcat 5.5\common\lib,然后restart tomcat就解决了。
============================================================================
2.
但是接着又出现了如下问题:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hsid' defined in? ServletContext resource [/WEB-INF/classes/applicationContext.xml]: Invocation of init method failed; nested? exception is java.lang.NoSuchMethodError: org.objectweb.asm.ClassVisitor.visit (IILjava/lang/String;Ljava/lang/String;[Ljava/lang/String;Ljava/lang/String;)V
从网上查了一下原因可能是:由于Spring和Hibernate共用了一些jar包引发的错误。

我从import进来的jar包:
Spring 2.0 AOP Libraries\asm-2.2.3.jar\org.objectweb.asm\ClassVisitor.class\ 有 visit()
Hibernate 3.1 Core Libraries\asm.jar\org.objectweb.asm\ClassVistor.class\ 也有visit(),但参数不同

第一种解决方法:
把WEB-INF\lib里面的3个jar包去掉,然后重启tomcat就可以了,不过每次deploy完,都要做这个delete的动作,很麻烦。
asm.jar
asm-attrs.jar
cglib-2.1.3.jar

第二种解决方法:
菜单 windows->preferences->Myeclipse->project Capabilities->Hibernate
->选择你使用的Hibernate版本(这里选3.1)->library modules 选 Core Libraries
->分别展开以上3个jar包->servlet deployment exclude->点击EDIT
选择你不想deploy到的服务器 ->保存即可
再部署的时候这个包就不会出现在/web-inf/lib/下 等你需要时在这么改回来就可以了。



?

补注:
其中asm-2.2.3.jar与asm.jar存在类上的冲突!!!
使用其中之一或两者都使用,可能会出现如下错误:
java.lang.NoClassDefFoundError: org/objectweb/asm/CodeVisitor
java.lang.NoClassDefFoundError: org/objectweb/asm/commons/EmptyVisitor
java.lang.NoSuchMethodError: org.objectweb.asm.ClassVisitor.visit。。。。。。
============================================================================
3.
另外发现自从deploy shblog project后,当我shutdown tomcat server时会有以下类似异常:
信息: Illegal access: this web application instance has been stopped already.? Could not load?
java.net.BindException.? The eventual following stack trace is caused by an error thrown for debugging purposes as
well as to attempt to terminate the thread which caused the illegal access, and has no functional impact.
java.lang.IllegalStateException
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1272)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1232)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
at com.mysql.jdbc.CommunicationsException.<init>(CommunicationsException.java:161)
at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:2759)
at com.mysql.jdbc.MysqlIO.quit(MysqlIO.java:1410)
at com.mysql.jdbc.Connection.realClose(Connection.java:4947)
at com.mysql.jdbc.Connection.cleanup(Connection.java:2063)
at com.mysql.jdbc.Connection.finalize(Connection.java:3403)
at java.lang.ref.Finalizer.invokeFinalizeMethod(Native Method)
at java.lang.ref.Finalizer.runFinalizer(Finalizer.java:83)
at java.lang.ref.Finalizer.access$100(Finalizer.java:14)
at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:160)
原因是:
Question: What causes these frequent Tomcat catalina.log messages "INFO: Illegal access: this web application instance has been stopped already."? I do not want to disable INFO level logging, so it would be nice to stop the root of the problem. I tried disabling RSS and Lucence and they still keep coming out. The full log entry looks like this: May 8, 2005 9:34:09 PM org.apache.catalina.loader.WebappClassLoader loadClass INFO: Illegal access: this web application instance has been stopped already. Could not load org.xml.sax.helpers.XMLReaderFactory. The eventual following stack trace is caused by an error thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access, and has no functional impact.
A:I found this explanation from web: It is possible that this is caused by Tomcat unsuccessfully reloading the web application. The app is unloaded, but all threads don't get shut down properly. As a result, when the threads try to run, they get clobbered by the fact that Tomcat has shut down its classloader, and an error is logged. The best fix is to turn off automatic webapp reloading for the application: in Tomcat's server.xml , find the <Context> declaration, and ensure it is set to: reloadable="false"
翻译一下上面的分析及解决方法:
原因:tomcat重新装载web应用程序失败导致的。当应用程序卸载时,并不会关闭所有的线程。当tomcat已经关闭了其类加载器后,一些线程依然会继续运行,这样就导致出错,这些错误就会被到日志文件里。
解决方法是:修改tomcat目录下conf文件夹下的server.xml,找到<Context>标签,把reloadble的属性值设为:reloadable="false"

2009-10-20
当在jsp input dairy detail and submit it, 发现那些回车符没有更新到数据库,所以在更新之前,用string = “<pre>”+string+”</pre>” 来保留数据的格式,然后在重新拿这份dairy出来前,再用String changeContent = instance.getContent().replaceAll(“<pre>”,””).replaceAll(“</pre>”,””); instance.setContent(changeContent), 最后在把这个blogInfo instance 返回给BlogController, 最后通过request.setAttribute()把它发给对应的jsp来显示。

** notes: replaceAll() 并不能改变原来字符串的值,所以要把replace之后的值保存到一个新的string 变量。
String changeContent = instance.getContent().replaceAll(“<pre>”,””).replaceAll(“</pre>”,””);

?

  相关解决方案