Java Servlet + Spring 配置中所遇问题以及处理

项目中需要使用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.csdn.net/arielxp/archive/2005/03/02/308272.aspx

Spring在Web项目的布置
http://book.51cto.com/art/200808/86776.htm

Spring的简单入门教程
http://dev.csdn.net/author/glchengang/1215c7c6f2d440e59df24cb10940b606.html

在Servlet中注入Spring容器
http://hhlux.javaeye.com/blog/492435

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值