高分求解Spring配置问题,在线等解答!

kosora曹 2013-07-22 03:23:24
公司的项目需要重构---把原来的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;
}


是循环引用的问题?还是其他问题?欢迎高手解答!
...全文
135 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
zqf3940 2013-07-22
  • 打赏
  • 举报
回复
加了@Autowired注解不需要get,set方法啊
  • 打赏
  • 举报
回复
看看set 和 get方法类型是否一致吧。
kosora曹 2013-07-22
  • 打赏
  • 举报
回复
引用 6 楼 Chen_yanxia 的回复:
注入的时候出错了 还有配置 看清楚啊
xml文件里的错误吗?
kosora曹 2013-07-22
  • 打赏
  • 举报
回复
引用 5 楼 fangmingshijie 的回复:
action层看下呢

@Controller
public class CountryAction extends CommonAction {

    /** serialVersionUID. */
    private static final long serialVersionUID = 557943713629501919L;

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

@Controller
public class RegionAction extends CommonAction {
    /** serialVersionUID. */
    private static final long serialVersionUID = 557943713629501919L;

    private Region region;
    private Country country;
   
    private RegionService regionService;

    /* private CountryProvideImpl countryProvideImpl; */

    /**
     * @param regionService the regionService to set
     */
    @Autowired
    public void setRegionService(RegionService regionService) {
        this.regionService = regionService;
    }
}
Fate- 2013-07-22
  • 打赏
  • 举报
回复
注入的时候出错了 还有配置 看清楚啊
  • 打赏
  • 举报
回复
action层看下呢
kosora曹 2013-07-22
  • 打赏
  • 举报
回复
引用 3 楼 fangmingshijie 的回复:
你这业务层有点乱啊,只保留@Service,后面知道的接口都删掉。业务接口应该注入到action层中。
我也这么觉得,这是新接手的项目,有很多的serivice互相调用的情况,如果全部重构的话,可能需要花一定的时间。
  • 打赏
  • 举报
回复
你这业务层有点乱啊,只保留@Service,后面知道的接口都删掉。业务接口应该注入到action层中。
kosora曹 2013-07-22
  • 打赏
  • 举报
回复
引用 1 楼 fangmingshijie 的回复:
把你provinceService贴出来看看,应该是命名或者set方法搞错了。
现在我把@autowired放到set上面了: 接口

/*
 * Copyright (c) 2012-2032 Accounting Center of China Aviation(ACCA).
 * All Rights Reserved.
 */
package cn.com.acca.cmrm.master.app.service;

import cn.com.acca.ajaf.core.exception.BusinessException;
import cn.com.acca.ajaf.core.service.IBaseService;
import cn.com.acca.cmrm.master.app.entity.Province;

/**
 * 省份Service接口层.
 * 
 * @version cmrm-web v1.0
 * @author Wu Yang, 2013-5-27
 */
public interface ProvinceService extends IBaseService<Province> {

    /**
     * 判断省份代码是否存在,存在为true,不存在为false.
     * @param provinceCode 省份代码.
     * @return true or false.
     * @throws BusinessException BusinessException.
     */
    boolean isExisted(String provinceCode) throws BusinessException;
    
    /**
     * 按照地理地区代码查询,是否存在省份信息.
     * @param regionId 地理地区Id.
     * @return List.
     * @throws Exception Exception.
     */
    boolean isExisteProvinceByRegion(String regionId) throws Exception;
    
    /**
     * 添加单条数据.
     * @param province .
     * @param regionCode .
     * @return boolean.
     * @throws Exception .
     */
    boolean saveProvince(Province province, String regionCode) throws BusinessException;
    
    /**
     * 编辑单条数据.
     * @param province .
     * @param regionCode .
     * @throws Exception .
     */
    void updateProvince(Province province, String regionCode) throws BusinessException;
    
    /**
     * 删除单条数据.
     * @param clazz .
     * @param provinceId .
     * @return boolean.
     * @throws Exception .
     */
    boolean deleteProvince(Class<Province> clazz, String provinceId) throws BusinessException;
    
}

实现类:

@Service("provinceService")
public class ProvinceServiceImpl extends BaseService<Province> implements ProvinceService {
   
    private RegionService regionService;

    /**
     * @param regionService the regionService to set
     */
    @Autowired
    public void setRegionService(RegionService regionService) {
        this.regionService = regionService;
    }
//其他实现方法
}
  • 打赏
  • 举报
回复
把你provinceService贴出来看看,应该是命名或者set方法搞错了。

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧