`
taro
  • 浏览: 135683 次
  • 性别: Icon_minigender_1
  • 来自: 东京
社区版块
存档分类
最新评论

配置struts2.0项目遇到的问题

阅读更多
   本来很简单的struts项目部署,却花掉我整整一天时间,归根结底问题出在struts2-spring-plugin-2.0.6.jar包身上。
先描述一下出现的问题吧:
    1、启动项目后就报HTTP Status 404 错误,也就是tomcat中找不到文件错误(NOT FOUND),所有的JSP页面都无法访问。
    2、控制台的输出:
严重: Exception starting filter struts2
Unable to load bean: type:com.opensymphony.xwork2.ObjectFactory class:org.apache.struts2.spring.StrutsSpringObjectFactory - bean - jar:file:/D:/Eclipse%20workspaces/MyEclipse%207.1%20for%20Struts2.0%20workspace%20(1)/.metadata/.me_tcat/webapps/emaileProject/WEB-INF/lib/struts2-spring-plugin-2.0.6.jar!/struts-plugin.xml:8:132
...省略...
Caused by: java.lang.NoClassDefFoundError: org/springframework/context/ApplicationContextAware
... 33 more

      说明是缺少org.springframework.context.ApplicationContextAware类,但是我配置的是一个Struts2.0+Hibernate的项目,并没有用到Spring,为什么在服务器加载Struts2.0的过程中涉及到Spring呢?
问题解决:
折腾了一天,从诊断web.xml struts.xml到不断尝试新建workspace...
最终发现,问题居然是struts2-spring-plugin-2.0.6.jar这个是用于struts2.0与Spring整合的包,如果项目中没有用到Spring,就不要引入这个包,并且这个包也不能放在WEB-INF\lib文件夹里,只要lib下面有struts2-spring-plugin-2.0.6.jar包,就会对Spring进行监听,就会报上面出现的错误...

补充:(我在JavaEye上找到struts2-spring-plugin包的作用,不知道对不对,接下来验证)
struts2与spring的整合。导入struts2-spring-plugin包,在web.xml中设置spring的监听器,
       spring监听器对应的API类为:org.springframework.web.context.ContextLoaderListener。
       struts2-spring-plugin包为我们将struts2的对象工厂设置为spring的IoC容器,其代码为:
       <struts>
      <bean type="com.opensymphony.xwork2.ObjectFactory" name="spring" class="org.apache.struts2.spring.StrutsSpringObjectFactory" />
    
      <!-- Make the Spring object factory the automatic default -->
      <constant name="struts.objectFactory" value="spring" />
 
      <package name="spring-default">
          <interceptors>
              <interceptor name="autowiring" class="com.opensymphony.xwork2.spring.interceptor.ActionAutowiringInterceptor"/>
              <interceptor name="sessionAutowiring" class="org.apache.struts2.spring.interceptor.SessionContextAutowiringInterceptor"/>
          </interceptors>
      </package>  
   </struts>
   很明显,将struts.objectFactory定位为org.apache.struts2.spring.StrutsSpringObjectFactory
   其余的工作就交给spring的IoC容器去做了。
   另外:当我们需要增加spring的配置文件时,需要在web.xml中设定contextConfigLocation参数。代码如下:
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>其他的spring配置文件名,用逗号隔开</param-value>
    </context-param>
1
0
分享到:
评论

相关推荐

    struts2.0非常实用的学习实例 本人自己精心准备

    "struts2.0做文件上传关于所加载的错误包造成的问题心得" 1:commons-io-1.4.jar 做上传时,如果用的该包是1.0的就经常出经上传不成功问题 2:commons-fileupload-1.2.1.jar 做上传时,如果用的该包是1.0的就也经常出...

    Struts2.0+Springframework2.5+ibatis2.3完美整合用户登录及增删改查

    希望能给更多喜欢这些框架的朋友带来帮助,如果在做此示例中遇到任何问题,都可直接在我的博客中留言,在随后的时间里,我会将此篇文章的详细制作过程发布到我的博客文章中去,希望各位朋友支持并关注我的博客!...

    Struts2权威指南完整版

    Struts 2.1抛弃了Codebehind插件提供的“零配置”支持,改为使用Convention插件提供“零配置”,Struts 2.1新增了Portlet支持……为了让众多Struts学习者、工作者快速从Struts 2.0的开发升级到Struts 2.1,笔者升级...

    Struts 2.1 权威指南 part13 pdf

    Struts 2.1抛弃了Codebehind插件提供的“零配置”支持,改为使用Convention插件提供“零配置”,Struts 2.1新增了Portlet支持……为了让众多Struts学习者、工作者快速从Struts 2.0的开发升级到Struts 2.1,笔者升级...

    Struts 2.1 权威指南 part04 pdf

    Struts 2.1抛弃了Codebehind插件提供的“零配置”支持,改为使用Convention插件提供“零配置”,Struts 2.1新增了Portlet支持……为了让众多Struts学习者、工作者快速从Struts 2.0的开发升级到Struts 2.1,笔者升级...

    Struts 2.1 权威指南 part01 pdf

    Struts 2.1抛弃了Codebehind插件提供的“零配置”支持,改为使用Convention插件提供“零配置”,Struts 2.1新增了Portlet支持……为了让众多Struts学习者、工作者快速从Struts 2.0的开发升级到Struts 2.1,笔者升级...

    Struts 2.1 权威指南 part02 pdf

    Struts 2.1抛弃了Codebehind插件提供的“零配置”支持,改为使用Convention插件提供“零配置”,Struts 2.1新增了Portlet支持……为了让众多Struts学习者、工作者快速从Struts 2.0的开发升级到Struts 2.1,笔者升级...

    Struts 2.1 权威指南 part06 pdf

    Struts 2.1抛弃了Codebehind插件提供的“零配置”支持,改为使用Convention插件提供“零配置”,Struts 2.1新增了Portlet支持……为了让众多Struts学习者、工作者快速从Struts 2.0的开发升级到Struts 2.1,笔者升级...

    Struts 2.1 权威指南 part03 pdf

    Struts 2.1抛弃了Codebehind插件提供的“零配置”支持,改为使用Convention插件提供“零配置”,Struts 2.1新增了Portlet支持……为了让众多Struts学习者、工作者快速从Struts 2.0的开发升级到Struts 2.1,笔者升级...

    Struts 2.1 权威指南 part05 pdf

    Struts 2.1抛弃了Codebehind插件提供的“零配置”支持,改为使用Convention插件提供“零配置”,Struts 2.1新增了Portlet支持……为了让众多Struts学习者、工作者快速从Struts 2.0的开发升级到Struts 2.1,笔者升级...

    Struts 2.1 权威指南 part11 pdf

    Struts 2.1抛弃了Codebehind插件提供的“零配置”支持,改为使用Convention插件提供“零配置”,Struts 2.1新增了Portlet支持……为了让众多Struts学习者、工作者快速从Struts 2.0的开发升级到Struts 2.1,笔者升级...

    Struts 2.1 权威指南 part12 pdf

    Struts 2.1抛弃了Codebehind插件提供的“零配置”支持,改为使用Convention插件提供“零配置”,Struts 2.1新增了Portlet支持……为了让众多Struts学习者、工作者快速从Struts 2.0的开发升级到Struts 2.1,笔者升级...

    Struts 2.1 权威指南 part10 pdf

    Struts 2.1抛弃了Codebehind插件提供的“零配置”支持,改为使用Convention插件提供“零配置”,Struts 2.1新增了Portlet支持……为了让众多Struts学习者、工作者快速从Struts 2.0的开发升级到Struts 2.1,笔者升级...

    Struts 2.1 权威指南 part07 pdf

    Struts 2.1抛弃了Codebehind插件提供的“零配置”支持,改为使用Convention插件提供“零配置”,Struts 2.1新增了Portlet支持……为了让众多Struts学习者、工作者快速从Struts 2.0的开发升级到Struts 2.1,笔者升级...

    Struts 2.1 权威指南 part09 pdf

    Struts 2.1抛弃了Codebehind插件提供的“零配置”支持,改为使用Convention插件提供“零配置”,Struts 2.1新增了Portlet支持……为了让众多Struts学习者、工作者快速从Struts 2.0的开发升级到Struts 2.1,笔者升级...

    Struts 2.1 权威指南 part08 pdf

    Struts 2.1抛弃了Codebehind插件提供的“零配置”支持,改为使用Convention插件提供“零配置”,Struts 2.1新增了Portlet支持……为了让众多Struts学习者、工作者快速从Struts 2.0的开发升级到Struts 2.1,笔者升级...

    java面试题

    72.8. struts2.0的常用标签 71 72.9. action是单实例还是多实例,为什么? 73 72.10. Struts的validate框架是如何验证的? 74 72.11. dispatchAction是用什么技术实现的? 74 72.12. struts2.0的mvc模式?与struts...

    iuhyiuhkjh908u0980

    最近在部署应用时,遇到一个问题,就是ant脚本登录到linux机器上执行部署命令时,不知如何去写脚本。不知有没有哪位同学做过?以下是我的ant脚本: &lt;project name="taxs_Admin" default="usage"&gt; ...

    JAVA上百实例源码以及开源项目源代码

    Java 源码包 Applet钢琴模拟程序java源码 2个目标文件,提供基本的音乐编辑功能。编辑音乐软件的朋友,这款实例会对你有所帮助。 Calendar万年历 1个目标文件 EJB 模拟银行ATM流程及操作源代码 ...

Global site tag (gtag.js) - Google Analytics