Spring 无法在扩展DAO和管理器接口上自动关联字段

Spring 无法在扩展DAO和管理器接口上自动关联字段,spring,spring-annotations,Spring,Spring Annotations,您好,我的应用程序运行良好,但在扩展我的管理器和Dao接口时,我遇到了错误。我尝试过在各种帖子中发布的解决方案(将更改为),但这给了我堆栈溢出错误。我认为在扩展接口时需要一些注释,但我不知道应该在那里使用什么注释。请引导我 //控制器 @Controller public class Controller { @Autowired private Manager2<Entity> manager; stackoverflow问题的发生是因为此代码 @Service

您好,我的应用程序运行良好,但在扩展我的管理器和Dao接口时,我遇到了错误。我尝试过在各种帖子中发布的解决方案(将
更改为
),但这给了我
堆栈溢出错误。我认为在扩展接口时需要一些注释,但我不知道应该在那里使用什么注释。请引导我

//控制器

@Controller
public class Controller {

    @Autowired
    private Manager2<Entity> manager;

stackoverflow问题的发生是因为此代码

@Service
public class ManagerImpl implements Manager2<Entity>  {
    @Autowired
    private Manager2<Entity> dao;
}
@服务
公共类ManagerImpl实现Manager2{
@自动连线
私人经理2道;
}
这种行为的原因是,存在一种永远无法解决的递归依赖关系。服务需要另一个具有相同bean配方的服务。 此外,
@autowired
注释用于按类型解析依赖关系。这意味着拥有2个保存类型的实例化bean会导致错误,因为spring无法理解您真正需要的bean。在这种情况下,您可以使用
@Resource
(byName)或添加带有所需bean名称的
@Qualifier
注释

public interface DAO1 <T> {
    public void add(T entity);
    public List<T> getAll();
    public T getById(Integer id);
    public void delete(Integer id);
    public void update(T entity);
}

public interface DAO2<T> extends  DAO1<T>  {
    public List<Entity> getList(int Id);
}

public class DaoImpl implements DAO2<Entity>  {
    @Autowired
    private SessionFactory sessionFactory;
}
<context:component-scan base-package="com.controller" />
<bean id="dao" class="com.dao.DaoImpl"></bean>
<bean id="manager" class="com.service.ManagerImpl"></bean>
nested exception is `org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.service.Manager2] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}`
@Service
public class ManagerImpl implements Manager2<Entity>  {
    @Autowired
    private Manager2<Entity> dao;
}