spring注解方式baseService中如何注入baseDao的问题

public abstract class BaseDao<E extends BaseEntity> extends JpaDaoSupport {

    /**
     * 创建实体
     * 
     * @param entity
     */
    public void insert(E entity) {
        entity.setCreateTime(DateTimeUtil.currentTime());
        getEntityManager().persist(entity);
    }
}
 
@Transactional(propagation=Propagation.REQUIRED)
public abstract class BaseService<E extends BaseEntity> {
	
	protected BaseDao<E> dao;

	public void setDao(BaseDao<E> dao) {
		this.dao = dao;
	}

	public BaseDao<E> getDao() {
		return dao;
	}
	/*
	 * 新增
	 */
	public void insert(E obj) {
		dao.insert(obj);
	}

}
 
@Repository("reasonDao")
public class ReasonDao extends BaseDao<Reason> {

}
 
public interface ReasonService extends IBaseService<Reason> {

}
 
@Transactional
@Service("reasonService")
public class ReasonServiceImpl extends BaseService<Reason> implements ReasonService {

    @Resource(name = "reasonDao")
    private ReasonDao reasonDao;

    }
 
@Transactional
@Service("reasonService")
public class ReasonServiceImpl extends BaseService<Reason> implements ReasonService {

    @Resource(name = "reasonDao")
    private ReasonDao reasonDao;
    
     @Resource(name = "reasonDao")
    public void setDao(BaseDao<Reason> dao) {
        super.setDao(dao);
    }
}

你可能感兴趣的:(spring 泛型 注解)