当前位置: 代码迷 >> Java Web开发 >> Spring Struts调整 Action注入不进来
  详细解决方案

Spring Struts调整 Action注入不进来

热度:127   发布时间:2016-04-13 22:23:54.0
Spring Struts整合 Action注入不进来
本帖最后由 shf4715 于 2015-10-02 14:18:11 编辑
实在找不到怎么回事了,貌似spring没起作用,本地测试类是有效的,文件应该是没错,大神们帮忙找找,小弟感激不尽
严重: Exception starting filter struts2
Unable to load configuration. - action - file:/opt/apache-tomcat-8.0.22/webapps/shop/WEB-INF/classes/indi/shop/action/main-defalut.xml:5:42

Caused by: Action class [mainAction] not found - action - file:/opt/apache-tomcat-8.0.22/webapps/shop/WEB-INF/classes/indi/shop/action/main-defalut.xml:5:42

产生错误的文件 main-defalut.xml:


<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<package name="main-default" namespace="/" extends="struts-default">
<action name="main" class="mainAction">
<result name="success">/WEB-INF/jsp/index.jsp</result>
</action>
</package>
</struts>    



struts.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<include file="indi/shop/action/main-defalut.xml"></include>
<include file="indi/shop/action/validate-defalut.xml"></include>
</struts> 


web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
  <display-name>shop</display-name>
  <filter>
    <filter-name>struts2</filter-name>
    <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>*.action</url-pattern>
  </filter-mapping>
  
<listener>
     <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
     <param-name>contextConfigLocation</param-name>
     <param-value>classpath:applicationContext.xml</param-value>
</context-param>

</web-app>


springContext.xml配置:

<!-- 扫描组件 -->
<context:component-scan base-package="indi.shop.action.*"></context:component-scan>

目标Action:

@Controller("mainAction")
public class MainAction {

public String execute() {
return "success";
}
}

------解决思路----------------------
缺少
struts2-spring-plugin-2.3.8.jar

------解决思路----------------------
配置文件写成
<context:component-scan base-package="indi.shop.action">
  相关解决方案