struts2_spring整合出错问题

Posted 雪落无痕1

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了struts2_spring整合出错问题相关的知识,希望对你有一定的参考价值。

启动服务器时出现异常:

警告: Failed startup of context [email protected]b11{/,E:/workspace/uploadPhoto/war}

Class: com.opensymphony.xwork2.spring.SpringObjectFactory
File: SpringObjectFactory.java
Method: getClassInstance
Line: 209 - com/opensymphony/xwork2/spring/SpringObjectFactory.java:209:-1
Caused by: java.lang.NullPointerException  at com.opensymphony.xwork2.spring.SpringObjectFactory.getClassInstance(SpringObjectFactory.java:209)

原因两个:
1.lib中多导入包的大原因:去掉struts2-spring-plugin-2.1.8包即可,因为没有用到spring。
2.还有的原因是用spring了,却没加监听器,在web.xml里面加上
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

所以最后总结:struts2——spring整合,控制台会输出两次spring初始化信息提示信息:

Starting Servlet Engine: Apache Tomcat/6.0.13
2011-3-9 18:29:36 org.apache.catalina.core.ApplicationContext log
信息: Initializing Spring root WebApplicationContext
log4j:WARN No appenders could be found for logger (org.springframework.core.CollectionFactory).
log4j:WARN Please initialize the log4j system properly.
2011-3-9 18:29:50 org.apache.catalina.core.ApplicationContext log
信息: Initializing Spring root WebApplicationContext
2011-3-9 18:30:01 org.apache.coyote.http11.Http11Protocol start
信息: Starting Coyote HTTP/1.1 on http-8080

1要用struts-spring整合(action交给spring管理),就得声明action类@component(“actionname”),而且要在web.xml加监听器;

2要是不用整合,就绝不能要整合的包

 

 

 

上面的总结有点小错误:以前我说控制台会出现两次加载spring,是myeclipse默认的tomcat服务的错误(其实是我自己以前项目遗留下来的文件影响的),默认的tomcat在服务目录中会实在myeclipse的工作目录中的.metadata目录;把它删除了就不会有以上的错误!删除了之后,运行项目还会变快哦~~
























以上是关于struts2_spring整合出错问题的主要内容,如果未能解决你的问题,请参考以下文章

spring+MVC整合的时候出错

使用Maven搭建Struts2+Spring3+Hibernate4的整合开发环境

spring和struts整合中注意的问题

Spring与Struts2整合

struts与spring整合

struts和spring整合