首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2EE开发 >

高分求解Spring配置有关问题,解答

2013-09-11 
高分求解Spring配置问题,在线等解答!公司的项目需要重构---把原来的XML里边的bean配置全都换成注入注解,现

高分求解Spring配置问题,在线等解答!
公司的项目需要重构---把原来的XML里边的bean配置全都换成注入注解,现在报以下错误:
(MSC service thread 1-2) Context initialization failed: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'iataSectionService' defined in "/D:/cmrm/CMRM/jboss-as-7.1.1.Final/jboss-as-7.1.1.Final/standalone/deployments/cmrm-web.war/WEB-INF/lib/cmrm-master-1.0.0-SNAPSHOT.jar/applicationContext-master.xml": 
Cannot resolve reference to bean 'countryService' while setting bean property 'countryService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'countryService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private cn.com.acca.cmrm.master.app.service.RegionService cn.com.acca.cmrm.master.app.service.impl.CountryServiceImpl.regionService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'regionService' defined in "/D:/cmrm/CMRM/jboss-as-7.1.1.Final/jboss-as-7.1.1.Final/standalone/deployments/cmrm-web.war/WEB-INF/lib/cmrm-master-1.0.0-SNAPSHOT.jar/applicationContext-master.xml": Cannot resolve reference to bean 'provinceService' while setting bean property 'provinceService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'provinceService' defined in "/D:/cmrm/CMRM/jboss-as-7.1.1.Final/jboss-as-7.1.1.Final/standalone/deployments/cmrm-web.war/WEB-INF/lib/cmrm-master-1.0.0-SNAPSHOT.jar/applicationContext-master.xml": Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'countryService' of bean class [cn.com.acca.cmrm.master.app.service.impl.ProvinceServiceImpl]: Bean property 'countryService' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?

at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:329) [spring-beans-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:107) [spring-beans-3.2.2.RELEASE.jar:3.2.2.RELEASE]


at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1393) [spring-beans-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1134) [spring-beans-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:522) [spring-beans-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461) [spring-beans-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295) [spring-beans-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223) [spring-beans-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292) [spring-beans-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) [spring-beans-3.2.2.RELEASE.jar:3.2.2.RELEASE]

关于CountryServiceImpl和RegionServiceImpl,出现了循环引用:


@Service("countryService")
public class CountryServiceImpl extends BaseService<Country> implements CountryService {
    @Autowired
    private RegionService regionService;
    @Autowired
    private AreaService areaService;

    /**
     * @param regionService the regionService to set
     */
    public void setRegionService(RegionService regionService) {
        this.regionService = regionService;
    }

    /**
     * @param areaService the areaService to set
     */
    public void setAreaService(AreaService areaService) {
        this.areaService = areaService;
    }




@Service("regionService")
public class RegionServiceImpl extends BaseService<Region> implements RegionService {


   @Autowired
    private CountryService countryService;

    /**
     * @param countryService the countryService to set
     */
    public void setCountryService(CountryService countryService) {
        this.countryService = countryService;
    }


是循环引用的问题?还是其他问题?欢迎高手解答! Spring Bean 异常 Java 注入注解
[解决办法]
把你provinceService贴出来看看,应该是命名或者set方法搞错了。
[解决办法]
你这业务层有点乱啊,只保留@Service,后面知道的接口都删掉。业务接口应该注入到action层中。
[解决办法]
action层看下呢
[解决办法]
注入的时候出错了  还有配置  看清楚啊
[解决办法]
看看set 和 get方法类型是否一致吧。
[解决办法]
加了@Autowired注解不需要get,set方法啊

热点排行