struts2+spring 注解注入时报错

http://sys-ks-cnm.iteye.com/blog/1884623

 

Unable to instantiate Action, LoginAction,  defined for 'Login' in namespace '/'LoginAction 
com.opensymphony.xwork2.DefaultActionInvocation.createAction(DefaultActionInvocation.java:307) 
com.opensymphony.xwork2.DefaultActionInvocation.init(DefaultActionInvocation.java:388) 
com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:187) 
org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:61) 
org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39) 
com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:47) 
org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:478) 
org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77) 
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)
root cause 

java.lang.ClassNotFoundException: LoginAction 
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1701) 
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1546) 
com.opensymphony.xwork2.util.ClassLoaderUtil.loadClass(ClassLoaderUtil.java:146) 
com.opensymphony.xwork2.ObjectFactory.getClassInstance(ObjectFactory.java:96) 
com.opensymphony.xwork2.spring.SpringObjectFactory.getClassInstance(SpringObjectFactory.java:212) 
com.opensymphony.xwork2.spring.SpringObjectFactory.buildBean(SpringObjectFactory.java:132) 
com.opensymphony.xwork2.ObjectFactory.buildBean(ObjectFactory.java:139) 
com.opensymphony.xwork2.ObjectFactory.buildAction(ObjectFactory.java:109) 
com.opensymphony.xwork2.DefaultActionInvocation.createAction(DefaultActionInvocation.java:288) 
com.opensymphony.xwork2.DefaultActionInvocation.init(DefaultActionInvocation.java:388) 
com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:187) 
org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:61) 
org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39) 
com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:47) 
org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:478) 
org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77) 
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)



配置如下: 
applicationcontext.xml 
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">  
<property name="locations">  
<list>  
<value>/WEB-INF/spring/application.properties</value>  
</list>  
</property>  
</bean> 
     <import resource="/spring/beans-datasource.xml"/> 
     <import resource="/spring/beans-dao.xml"/> 
     <context:component-scan base-package="sshLogin" /> 

struts.xml 

<struts> 
<constant name="struts.enable.DynamicMethodInvocation" value="true" /> 
<constant name="struts.devMode" value="false" /> 
<package name="strutsLogin" namespace="" extends="struts-default"> 
<action name="Login" class="LoginAction" method="login"> 
<result name="success" type="redirectAction">List</result> 
<result name="input">error.jsp</result> 
</action> 

<action name="Regist" class="LoginAction" method="regist"> 
<result name="success" type="redirectAction">List</result> 
    <result name="show">update.jsp</result> 
<result name="input">index.jsp</result> 
</action> 

<action name="Update" class="LoginAction" method="update"> 
<result name="success" type="redirectAction">List</result> 
<result name="input">index.jsp</result> 
</action> 

<action name="Query" class="LoginAction" method="query"> 
<result name="success">update.jsp</result> 
</action> 
<action name="Delete" class="LoginAction" method="delete"> 
<result name="success"  type="redirectAction">List</result> 
<result name="input"  type="redirectAction">List</result> 
</action> 
</package> 
<package name="strutsList" namespace="" extends="struts-default"> 
<action name="List" class="LoginAction" method="list"> 
<result name="success">list.jsp</result> 
<result name="input">index.jsp</result> 
</action> 
</package> 


</struts> 


web.xml 
<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>/*</url-pattern> 
</filter-mapping> 
<context-param> 
        <param-name>contextConfigLocation</param-name> 
        <param-value>/WEB-INF/applicationContext.xml</param-value> 
    </context-param> 
   <listener> 
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
    </listener> 

java 代码 

@Controller("LoginAction") 
@Scope("prototype") 
public class LoginAction extends ActionSupport{ 

    /** 
     * 
     */ 
    private static final long serialVersionUID = 1L; 
    User user ; 
    @Autowired 
    LoginService  loginService; 
    List<User>  list =null; 
/** 
麻烦各位看下原因 是不是action没被spring托管 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值