注入自动装配的依赖项失败原因:org.springframework.beans.factory.BeanCreationException:

时间:2015-05-25 12:57:12

标签: java spring autowired

我正在开发一个小型Java EE Hibernate Spring应用程序,并出现以下错误:

  

严重:例外情况l l l en en en l l l l l l l   (上下文初始化)àl'instancede classe d'écoute(听众)   org.springframework.web.context.ContextLoaderListener   org.springframework.beans.factory.BeanCreationException:错误   创建名为'responsableServiceImpl'的bean:注入   自动连接依赖失败;嵌套异常是   org.springframework.beans.factory.BeanCreationException:不能   autowire字段:private com.drp.dao.ResponsableDao   com.drp.service.impl.ResponsableServiceImpl.responsableDao;嵌套   异常是org.springframework.beans.factory.BeanCreationException:   创建名为'responsableDaoImpl'的bean时出错:注入   自动连接依赖失败;嵌套异常是   org.springframework.beans.factory.BeanCreationException:不能   autowire字段:org.hibernate.SessionFactory   com.drp.dao.impl.GenericDaoImpl.sessionFactory;嵌套异常是   org.springframework.beans.factory.BeanCreationException:错误   在ServletContext中定义名为'sessionFactory'的bean   resource [/WEB-INF/applicationContext.xml]:调用init方法   失败;嵌套异常是org.hibernate.AnnotationException:   集合既没有泛型类型也没有OneToMany.targetEntity()   已定义:com.drp.model.Drp.decisions

     

引起:org.springframework.beans.factory.BeanCreationException:   无法自动装配字段:private com.drp.dao.ResponsableDao   com.drp.service.impl.ResponsableServiceImpl.responsableDao;嵌套   例外是
  org.springframework.beans.factory.BeanCreationException:错误   创建名为'responsableDaoImpl'的bean:注入自动装配   依赖失败;嵌套异常是   org.springframework.beans.factory.BeanCreationException:不能   autowire字段:org.hibernate.SessionFactory   com.drp.dao.impl.GenericDaoImpl.sessionFactory;嵌套异常是
  org.springframework.beans.factory.BeanCreationException:错误   在ServletContext中定义名为'sessionFactory'的bean   resource [/WEB-INF/applicationContext.xml]:调用init方法   失败;嵌套异常是org.hibernate.AnnotationException:   集合既没有泛型类型也没有OneToMany.targetEntity()   已定义:com.drp.model.Drp.decisions

ListResponsableBean.java:

package com.drp.beans;
import java.io.Serializable;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;

import com.drp.model.Responsable;
import com.drp.service.ResponsableService;

@Component
@ManagedBean(name="listResponsableBean")
@SessionScoped
public class ListResponsableBean  implements Serializable {
private static final long serialVersionUID = 6675856254221490117L;

@Autowired
private ResponsableService respService;

private List<Responsable> reponsables;

@PostConstruct
public void init() {
    reponsables = respService.getResponsable();
}

public ResponsableService getRespService() {
    return respService;
}   

public void setRespService(ResponsableService respService) {
    this.respService = respService;
}

public List<Responsable> getReponsables() {
    return reponsables;
}

public void setReponsables(List<Responsable> reponsables) {
    this.reponsables = reponsables;
}   

}

ResponsableDaoImpl.java

package com.drp.dao.impl;
import com.drp.dao.ResponsableDao;
import com.drp.model.Responsable;
import org.springframework.stereotype.Repository;

@Repository
public class ResponsableDaoImpl extends GenericDaoImpl<Responsable, Integer> implements ResponsableDao {

public ResponsableDaoImpl() {
    super(Responsable.class);
}

public ResponsableDaoImpl(Class<Responsable> type) {
    super(type);
}

}

GenericDaoImpl.java

package com.drp.dao.impl;

import java.io.Serializable;
import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.drp.dao.GenericDao;

public class GenericDaoImpl<T , I extends Serializable> implements GenericDao<T, I>{

@Autowired
SessionFactory sessionFactory;

private Class<T> type;

public GenericDaoImpl(Class<T> type){
    this.type = type;
}

public void setSessionFactory(SessionFactory sessionFactory) {
    this.sessionFactory = sessionFactory;
}    
public SessionFactory getSessionFactory() {
    return sessionFactory;
}
@SuppressWarnings("unchecked")
@Transactional(readOnly = true)
@Override
public T find(I id) {
    return (T) getSessionFactory().getCurrentSession().get(type, id);
}

@SuppressWarnings("unchecked")
@Transactional(readOnly = true)
public List<T> findAll(){

return (List<T>) getSessionFactory().getCurrentSession().createQuery("from "+type.getName()).list();        

}
@Transactional
@Override
public void delete(T obj) {
    getSessionFactory().getCurrentSession().delete(obj);

}
   @Transactional
@Override
public void saveOrUpdate(T obj) {
    getSessionFactory().getCurrentSession().saveOrUpdate(obj);
}    

}

ResponsableServiceImpl.java

package com.drp.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.drp.dao.ResponsableDao;
import com.drp.model.Responsable;
import com.drp.service.ResponsableService;

@Service
public class ResponsableServiceImpl implements ResponsableService {

@Autowired
private ResponsableDao responsableDao;  

@Override
public List<Responsable> getResponsable() {
    return responsableDao.findAll();

}

public ResponsableDao getResponsableDao() {
    return responsableDao;
}

public void setResponsableDao(ResponsableDao responsableDao) {
    this.responsableDao = responsableDao;
}

}

ResponsableService.java

package com.drp.service;
import java.util.List;
import com.drp.model.Responsable;

public interface ResponsableService {
public List <Responsable> getResponsable();

}

0 个答案:

没有答案