在struts2整合spring的时候,完全一步步按照官方文档上去做的,最后发现出现 Unable to instantiate Action,网上一搜发现很多人和我一样的问题,配置什么都没有错误,就是出现这个问题,其实这个原因很简单就是Spring容器没有启动,struts2容器到spring容器里面找Action的时候当然就找不到了。

  问题就出在web.xml配置的问题,按照struts2官方文档上面步骤,在web.xml里面配置加入以下代码:

<!-- Context Configuration locations for Spring XML files -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext-*.xml,classpath*:applicationContext-*.xml</param-value>
</context-param>

  问题就出在这里。我们知道struts2整合spring的时候, spring配置文件会默认为  /WEB-INF/applicationContext.xml 。但时如果我们加上上面的配置,当启动Spring容器的时候,它就会去 【/WEB-INF/】或者【/WEB-INF/classes/及其子目录(也就是classpath*)】下面查找以名字以 applicationContext-(注意有一个[-]) 为开头的spring配置文件。但是我们一般习惯性的将spring的配置文件起名为 applicatinContext.xml,所以是永远也加载不了这个文件啦。或者是没有加上如上的配置但是我们把spring配置文件放在类加载路径下,也无法加载了。

所以我们只要把【-】去掉就可以了

    <!-- Context Configuration locations for Spring XML files -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext*.xml,classpath*:applicationContext*.xml</param-value>
</context-param>

  就一切正常啦。

struts2整合spring出现的Unable to instantiate Action异常的更多相关文章

  1. SSH整合报错:Unable to instantiate Action, testAction, defined for 'test' in namespace '/'testAction

    报错如下: Struts Problem Report Struts has detected an unhandled exception: Messages: testAction Unable ...

  2. SSH整合:Unable to instantiate Action, employeeAction, defined for 'emp-list' in namespace '/'employeeAction - action

    SSH整合,照着视频敲的,不知为何会报错,经历了快两周的折磨给解决了.记录下来给后面需要帮助的人,也算极好的了. Struts Problem Report Struts has detected a ...

  3. struts2整合spring的思路

    struts2整合spring有有两种策略: >sping容器负责管理控制器Action,并利用依赖注入为控制器注入业务逻辑组件. >利用spring的自动装配,Action将自动会从Sp ...

  4. struts2整合spring应用实例

    我们知道struts1与spring整合是靠org.springframework.web.struts.DelegatingActionProxy来实现的,以下通过具体一个用户登录实现来说明stru ...

  5. Struts2—整合Spring

    Struts2—整合Spring Spring框架是一个非常优秀的轻量级java EE容器,大部分javaEE应用,都会考虑使用Spring容器来管理应用中的组件. Struts2是一个MVC框架,是 ...

  6. 报错HTTP Status 500 - Unable to instantiate Action

    报错如下: HTTP Status 500 - Unable to instantiate Action, visitAction, defined for 'visit_toAddPage' in ...

  7. HTTP Status 500 - Unable to instantiate Action, customerAction, defined for 'customer_toAddPage' i

    使用struts2时碰到这样的错误 HTTP Status 500 - Unable to instantiate Action, customerAction, defined for 'custo ...

  8. SSH Spring3\Java1.8 “Unable to instantiate Action, xxAction, defined for 'xxAction_login' in namespace '/'null”

    1.Stacktraces Unable to instantiate Action,xxAction, defined for 'xxAction_login' in namespace '/'nu ...

  9. Unable to instantiate Action, xxxAction, defined for 'xxxAction' in namespace '/'xxx

    最近写SSH2的项目时,遇到一些小问题,action得不到service实例,遂将struct2委托给spring进行管理,然后修改了bean的id和action的class,但是运行后发现找不到ac ...

随机推荐

  1. Python算法之---冒泡,选择,插入排序算法

    ''' Created on 2013-8-23    @author: codegeek '''    def bubble_sort(seq):     for i in range(len(se ...

  2. 快速查询本机IP 分类: windows常用小技巧 2014-04-15 09:28 138人阅读 评论(0) 收藏

    第一步: 点击windows建(屏幕左下方),在搜索程序和文件文本框内输入:cmd 第二步:      点击Enter建进入. 第三步: 输入:ipconfig即可. 版权声明:本文为博主原创文章,未 ...

  3. TCP/IP协议族-----10、搬家IP

  4. 把安卓源代码中的system app独立出来,像开发普通app那样开发

          个人建议首先依照android源码的ide/eclipse中的格式化xml和import导入到你编译的eclipse中,假设你编译的android源码是2.3以上的版本号的,建议用JDK6 ...

  5. [转] Maven镜像配置

    参考:许晓斌的<Maven实战> 镜像是为了提供更快的服务 如图:X就认为是Y的一个镜像. 编辑settings.xml配置中央仓库镜像: <settings> ... < ...

  6. Decorator Wrapper 装饰模式 包装

    简介 装饰模式 装饰模式以对客户端[透明]的方式[扩展]对象的功能,客户端并不会觉得对象在装饰前和装饰后有什么不同,是继承关系的一个替代方案. 若只为增加功能而使用继承,当基类较多时会导致继承体系越来 ...

  7. java.lang.ClassCastException

    是指类型转换出错 当前者的域小于后者的时候出现 譬如说:前者A是子类的对象,而后者B是父类的对象 若使用A = B;就会抛出java.lang.ClassCastException List<C ...

  8. Access数据库数据转换Table.Json

    使用WPF组件 xaml <Window x:Class="JsonConvert.MainWindow" xmlns="http://schemas.micros ...

  9. Android之fragment点击切换和滑动切换结合

    学了一小段时间的Android,主要接触的是UI设计,打交道最多莫过于fragment了吧.在Android3.0引入了fragment的概念后,几乎在所以的Android的应用中都可以看见其身影,已 ...

  10. oracle系统包——dbms job用法(oracle定时任务)

    用于安排和管理作业队列,通过使用作业,可以使ORACLE数据库定期执行特定的任务. 一.dbms_job涉及到的知识点1.创建job:variable jobno number;dbms_job.su ...