首页 新闻 赞助 找找看

Spring,Struts2注解+xml配置时动态调用方法失败

0
悬赏园豆:15 [已关闭问题] 关闭于 2017-02-14 10:57
 1 <?xml version="1.0" encoding="UTF-8" ?>
 2 <!DOCTYPE struts PUBLIC
 3     "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
 4     "http://struts.apache.org/dtds/struts-2.5.dtd">
 5 <struts>
 6     <constant name="struts.enable.DynamicMethodInvocation" value="true" />
 7     <constant name="struts.objectFactory" value="spring"  />
 8     <constant name="struts.action.extension" value="do"  />
 9 
10     <package name="spend" namespace="/user" extends="struts-default">
11 
12         <action name="account" class="com.kedia.ssh.action.EmployeeAction">
13             <result name="a">/a.html</result>
14             <result name="b">/b.html</result>
15         </action>
16         
17         <action name="a" class="com.kedia.ssh.action.EmployeeAction" method="a">
18             <result name="a">/a.html</result>
19         </action>
20         
21         <action name="test" class="com.kedia.ssh.action.EmployeeAction" method="input">
22             <result name="a">/a.html</result>
23             <result name="b">/b.html</result>
24         </action>
25         
26     </package>
27 </struts>
这是我的Struts.xml的配置
 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <beans xmlns="http://www.springframework.org/schema/beans"
 3     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
 4     xmlns:aop="http://www.springframework.org/schema/aop"
 5     xmlns:context="http://www.springframework.org/schema/context" 
 6     xmlns:tx="http://www.springframework.org/schema/tx"
 7     xsi:schemaLocation="http://www.springframework.org/schema/beans 
 8         http://www.springframework.org/schema/beans/spring-beans.xsd
 9         http://www.springframework.org/schema/aop 
10         http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
11         http://www.springframework.org/schema/context 
12         http://www.springframework.org/schema/context/spring-context-4.0.xsd
13         http://www.springframework.org/schema/tx 
14         http://www.springframework.org/schema/tx/spring-tx-4.0.xsd">
15 
16     <context:annotation-config/>
17     <context:component-scan base-package="com.kedia" />
18 
19 </beans>

这是Spring的配置applicationContext.xml文件的配置

 1 package com.kedia.spend.user.account.action;
 2 
 3 import org.apache.struts2.convention.annotation.Action;
 4 import org.apache.struts2.convention.annotation.Namespace;
 5 import org.apache.struts2.convention.annotation.ParentPackage;
 6 import org.apache.struts2.convention.annotation.Result;
 7 import org.apache.struts2.convention.annotation.Results;
 8 import org.springframework.context.annotation.Scope;
 9 import org.springframework.stereotype.Component;
10 
11 import com.opensymphony.xwork2.ActionSupport;
12 
13 @Component
14 @Scope("prototype")
15 @ParentPackage("struts-default")
16 @Namespace("/admin")
17 @Action("user")
18 @Results({
19     @Result(name="a", location="/a.html"),
20     @Result(name="b", location="/b.html") 
21 })
22 public class UserAction extends ActionSupport {
23 
24     private static final long serialVersionUID = 1L;
25 
26     public String a() {
27         return "a";
28     }
29     
30     public String b(){
31         return "b";
32     }
33 
34 }
注解action
 1 package com.kedia.ssh.action;
 2 
 3 import org.springframework.context.annotation.Scope;
 4 import org.springframework.stereotype.Component;
 5 
 6 import com.opensymphony.xwork2.ActionSupport;
 7 
 8 @Component("eaction")
 9 @Scope("prototype")
10 public class EmployeeAction extends ActionSupport {
11     
12     private static final long serialVersionUID = 1L;
13     
14     public String a(){
15         return "a";
16     }
17     
18     public String b(){
19         return "b";
20     }
21     
22     public String input(){
23         return INPUT;
24     }
25     
26 }
xml中配置的action

xml中配置的action可以使用action名+ .do的方式访问到,

但是使用动态调用方法的功能就不能访问了

使用 http://localhost:8080/ssh/user/test!a.do 访问的时候就会报错

错误信息是:

1 HTTP Status 404 - Invalid method: a for action test
2 
3 type Status report
4 
5 message Invalid method: a for action test
6 
7 description The requested resource is not available.
8 Apache Tomcat/7.0.72

各位路过的大神救急啊

问题补充:

各位大神指点下啊!!!

看你灬梨涡浅笑的主页 看你灬梨涡浅笑 | 初学一级 | 园豆:96
提问于:2017-02-09 12:18
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册