spring XML中
<bean id="CpinfoAction" class="com.pro.action.CpinfoAction">
<property name="serivce">
<ref bean="CpinfoSerivce" />
</property>
</bean>
struts XML中
<constant name="struts.objectFactory" value="spring" />
<action name="cpList" class="CpinfoAction"
method="cpList">
<result name="rs">/hou/houtai.jsp</result>
</action>
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,classpath*:applicationContext-*.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
所有的配置就这些 不知道是否有所遗漏,或是写错之处 望高手指教
Action中方法名没问题,有struts2-spring-plugin-2.1.6.jar
启动项目无异常
运行 Unable to instantiate Action, CpinfoAction, defined for 'cpList' in namespace '/'CpinfoAction
无法实例化CpinfoAction,定义为'cpList在命名空间'/'CpinfoAction
------解决方案--------------------
web.xml的配置貌似有些问题:
- XML code
<context-param><param-name>contextConfigLocation</param-name><param-value>/WEB-INF/applicationContext-*.xml,classpath*:applicationContext-*.xml</param-value></context-param>
------解决方案--------------------
你把这个jar也去掉试试看,不行那就悲剧了,不要急。慢慢找问题吧,程序编写考验耐心的。
------解决方案--------------------
<context:annotation-config />
这个放在applicationContext.xml里面的!!
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
<context:annotation-config />