我想在struts的Action里面注入多个Service?可是注入不进去,望大家指点一下,该怎么做?
这是一个企业信息Action 我想注入行业类型和企业类型的service   代码如下          @Autowired
private ComSitService comSitService;
//行业类型
@Autowired
    private IndustryService industryService;
//企业类型
@Autowired
private CorpTypeService corpTypeService;
 

解决方案 »

  1.   

    你action中提供了这些service 的setter方法了吗 自动装配的注解 你如果不是很清楚他的作用,请先用配置文件类来配吧。
      

  2.   


    那你就生成他的setter方法啊 
    public void setComSitService(ComSitService comSitService) {
    this.comSitService = comSitService;
    }
    public void setIndustryService(IndustryService industryService) {
    this.industryService = industryService;
    }
    public void setCorpTypeService(CorpTypeService corpTypeService) {
    this.corpTypeService = corpTypeService;
    }
      

  3.   

    注入是通过  凡是 使用set 和 get 方法进行的~~所以必须要有get set
    这些get set 都是自己写的 可不是生成的
      

  4.   

    @Autowired
        private ComSitService comSitService;
    这样注入是不需要get/set方法的
      

  5.   

    当然可以注入多个啊,你只要提供插口就可以了(set方法)
      

  6.   

    多少个service都可以,service提供setter即可
      

  7.   

    这个个注入的个数没有关系
    但是注入的话setter方法是要的
    getter方法的话 可以不要 
      

  8.   

    推荐看下这篇技术日记
    http://laoguo.blog.51cto.com/211591/108724
      

  9.   

    可以在一个action 中注入多个service ,只是每一个service 需要提供setters()方法,
    spring 中的注入就是用setters()方法注入的!
      

  10.   

    的确,注入需要提供它的setter 方法
      

  11.   

    若使用注解的话,可以不用setter/getter。
    注入不了,是不是bean配置文件忘了修改一下# <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"  
    #     xsi:schemaLocation="http://www.springframework.org/schema/beans  
    #     http://www.springframework.org/schema/beans/spring-beans-2.5.xsd  
    #     http://www.springframework.org/schema/context  
    #     http://www.springframework.org/schema/context/spring-context-2.5.xsd">  
    #     <context:annotation-config />  
    # </beans>