项目中需要使用Servlet和Spring,第一次弄这些东西,真是问题重重,把几个主要的问题记录下来,以备后用。
错误 1.
严重: Error configuring application listener of class org.springframework.web.context.ContextLoaderListener
java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
将spring.jar 考到Apache Software Foundation/Tomcat 6.0/lib目录中。
原理:
在Web.xml中引入org.springframework.web.context.ContextLoaderListener,启动Tomcat时,尚未引入该类,所以报错。
放入Tomcat的lib目录中,让Tomcat启动时就加载该类。
错误 2.
严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
将commons-logging-1.1.1.jar,考到Apache Software Foundation/Tomcat 6.0/lib目录中。
错误 3.
严重: Context initialization failed
org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [com.hylink.Chinese] for bean with name 'Chinese' defined in ServletContext resource [/WEB-INF/applicationContext.xml]; nested exception is java.lang.ClassNotFoundException: com.hylink.Chinese
这个是Eclipse 编译路径 造成的,默认的是在build/classes目录中,但是Spring只认识WebContent/WEB-INF/classes目录。故:在WebContent/WEB-INF/中创建classes目录,并在Java Build Path --> Source --> Default output folder 中设置编译路径为WebContent/WEB-INF/classes
——————————————————< END >————————————————————————
另外,学习中看到了一些资源,对做这件事帮助很大,记录如下:
Spring的安装
http://blog.youkuaiyun.com/arielxp/archive/2005/03/02/308272.aspx
Spring在Web项目的布置
http://book.51cto.com/art/200808/86776.htm
Spring的简单入门教程
http://dev.youkuaiyun.com/author/glchengang/1215c7c6f2d440e59df24cb10940b606.html
在Servlet中注入Spring容器
http://hhlux.javaeye.com/blog/492435