struts2 + spring 整合的问题 Action里面有iService的setter方法吗? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 action里面应有iService的getter和setter方法 你的代码贴的不全!我初步判断,应该问题出在以下几个地方,你可以参考一下:第一,<bean id="serviceAction" class="cn.test.action.ServiceAction" singleton="false"><property name="iService"><ref bean = "iService"/></property></bean> 这里的id属性要与struts.xml中的action的name属性一致;第二,你的Spring的事务管理模板好象形同虚设啊?正常它应该注入给服务类接口的,你的配置文件里只配置了服务类的实现类,没有服务类接口啊?难道你没有使用接口?如果你有接口,应该还有下面这个配置:<!-- Services --> <bean id ="iService" extends="继承一个抽象事务模板"> <property name ="target" > <ref bean ="指向实现类的bean的name属性" /> </property > </bean > 然后把这个bean注入给Action。第三,检查你的Action类,看看IService的对象iService是不是不小心写成这样的:IService iService=new IServiceImpl();这是新手接触Spring非常容易犯的错误,其原因是对IOC还没有很好的理解! 我没用过struts2.0,不过据说是从webwork迁移过来的。我对webwork有一点了解,如果从webwork的观点来看,好像ApplicationContext.xml里面不需要对Action进行配置,这是其一。其二,使用spring通过setter注入,在某些时候,setter的写法有一点特殊,和用eclipse自动完成的setter不同:比如iService,用eclipse生成的setter是setIService(IService iService);而Spring认可的setter是setiService(IService iService);楼主的问题可能就出在这里。另外还是建议不要写iService这样的属性。 我也遇到同样的问题,连工程都启动不起来,最后终于搞定:struts.xml:<action name="test" method="getAll" class="TestAction"> <result name="success">/success.jsp</result> </action>applicationContext.xml:<beans>.....<bean id="TestAction" class="presentation.TestAction" > <property name="testService"><ref bean="testService"/></property> </bean>......</beans>在action的class和application.xml中bean id的值一致,就可以找到service了,然后在TestAction中加一属性:private TestService testService;public void setTestService(TestService testService) { this.testService = testService;} 我也遇到这个问题了,我的action里面class的值和applicationContext里面action的id值是一样的,但是报的错误是找不到class的值。也就是applicationContext的Id值。 为什么Timer()有时会运行的慢呢?求解答 struts2+hibernate 做集成, 问一个 struts2 的菜鸟问题 Spring里使用QueryRunner如何进行事物处理 使用org.apache.xpath.XPathAPI解析XML的名字空间问题,高手请进! Hibernate问题 关于Jbuilder引用WebService的问题,顶也有分 字符串之间的转换? 问大家一个关于四级的问题! 运行在Tomcat下的系统近来总是丢文件??? 急 birt报表的DataSource问题 lucene 中的中文高亮显示问题
<property name="iService">
<ref bean = "iService"/>
</property>
</bean>
这里的id属性要与struts.xml中的action的name属性一致;第二,你的Spring的事务管理模板好象形同虚设啊?正常它应该注入给服务类接口的,你的配置文件里只配置了服务类的实现类,没有服务类接口啊?难道你没有使用接口?如果你有接口,应该还有下面这个配置:<!-- Services -->
<bean id ="iService" extends="继承一个抽象事务模板">
<property name ="target" >
<ref bean ="指向实现类的bean的name属性" />
</property >
</bean >
然后把这个bean注入给Action。第三,检查你的Action类,看看IService的对象iService是不是不小心写成这样的:IService iService=new IServiceImpl();这是新手接触Spring非常容易犯的错误,其原因是对IOC还没有很好的理解!
setIService(IService iService);而Spring认可的setter是setiService(IService iService);楼主的问题可能就出在这里。另外还是建议不要写iService这样的属性。
struts.xml:
<action name="test" method="getAll" class="TestAction">
<result name="success">/success.jsp</result>
</action>
applicationContext.xml:
<beans>
.....
<bean id="TestAction" class="presentation.TestAction" >
<property name="testService"><ref bean="testService"/></property>
</bean>
......
</beans>在action的class和application.xml中bean id的值一致,就可以找到service了,然后在TestAction中加一属性:
private TestService testService;
public void setTestService(TestService testService) {
this.testService = testService;
}