struts2_spring整合出错问题

来源:互联网 发布:hidpi canvas.min.js 编辑:程序博客网 时间:2024/05/05 22:01

启动服务器时出现异常:

警告: Failed startup of context com.google.apphosting.utils.jetty.DevAppEngineWebAppContext@1242b11{/,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目录;把它删除了就不会有以上的错误!删除了之后,运行项目还会变快哦~~

原创粉丝点击