一下两段代码是同一个项目中的。第一个问题:在下面代码中@Repository("topicIndexDao")是什么意思?@Repository("topicIndexDao")
public class TopicIndexDaoImpl extends GenericIndexDaoImpl<SearchableTopic> {}
-------------------------------------------------------------------------------------
第二个问题:在下面代码中@Resource(name = "topicIndexDao")和上面的代码中的@Repository("topicIndexDao")存在关系吗?public abstract class ServiceImplBase<T> extends DaoImplBase<T> implements ServiceBase<T> {
@Resource(name = "topicIndexDao")
protected GenericIndexDao<SearchableTopic> topicIndexDao;
}

解决方案 »

  1.   

    1。注解@Repository,说明这是一个受spring容器管理的bean定义,bean得名字是topicIndexDao
    2。@Resource应该是把名字为topicIndexDao的bean节点注入到GenericIndexDao里面
      

  2.   

    为什么不去查spring的文档??3.12.1. @Component and further stereotype annotationsBeginning with Spring 2.0, the @Repository annotation was introduced as a er for any class that fulfills the role or stereotype of a repository (a.k.a. Data Access Object or DAO). Among the possibilities for leveraging such a er is the automatic translation of exceptions as described in Section 12.6.4, “Exception Translation”.Spring 2.5 introduces further stereotype annotations: @Component, @Service and @Controller. @Component serves as a generic stereotype for any Spring-managed component; whereas, @Repository, @Service, and @Controller serve as specializations of @Component for more specific use cases (e.g., in the persistence, service, and presentation layers, respectively). What this means is that you can annotate your component classes with @Component, but by annotating them with @Repository, @Service, or @Controller instead, your classes are more properly suited for processing by tools or associating with aspects. For example, these stereotype annotations make ideal targets for pointcuts. Of course, it is also possible that @Repository, @Service, and @Controller may carry additional semantics in future releases of the Spring Framework. Thus, if you are making a decision between using @Component or @Service for your service layer, @Service is clearly the better choice. Similarly, as stated above, @Repository is already supported as a er for automatic exception translation in your persistence layer.