ss整合,创建action时,不会交给spring创建?
web.xml如下:<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<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,classpath*:applicationContext-*.xml
</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
</web-app>
struts.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<constant name="struts.objectFactory" value="spring"/>
<package name="struts" extends="struts-default">
<action name="registerAction" class="register">
<result name="success">/success.jsp</result>
<result name="input">/fail.jsp</result>
</action>
</package>
</struts>
applicationContent.xml:
<bean id="register" class="com.liupeng.action.RegisterDelAction" scope="prototype"></bean>
结果创建action时出这个异常:Unable to instantiate Action, register, defined for 'registerAction' in namespace '/'register
com.opensymphony.xwork2.DefaultActionInvocation.createAction(DefaultActionInvocation.java:319)
com.opensymphony.xwork2.DefaultActionInvocation.init(DefaultActionInvocation.java:400)
com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:194)
org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:63)
org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39)
com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:58)
org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:501)
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: register
struts2-spring-plugin-2.1.6.jar已经导入了
请教各位大侠,是哪里的问题啊! --------------------编程问答-------------------- 还要在struts.xml中配置一个常量:<constant name="struts2.ObjectFactory" value="Spring"/>
意义在于将struts中的action全部交给spring管理,所以struts并不实例化action,而是在spring
中配置bean属性进行依赖注入。 --------------------编程问答-------------------- <constant name="struts.objectFactory" value="spring"/>
我配置的这个不行?上面有啊 ! --------------------编程问答--------------------
不好意思,没注意看。一般都是这个问题了。那spring启动成功了吗?applicationContext文件正确读取了吗? --------------------编程问答-------------------- spring与struts2集成时,默认action都交给spring来管理。spring-struts2的插件已经帮你搞好了。 --------------------编程问答--------------------
应该是正确读取了,服务器启动的时候没异常! --------------------编程问答-------------------- 现在可以了,是jar包的问题,可能是jar包的版本有冲突吧!
补充:Java , Java EE