Spring注解@Component、@Repository、@Service、@Controller区别在哪?
2011-07-20 11:04
459 查看
@Component是通用的
@Repository、@Service、@Controller则是细化
那这几个注解到底有没有功能上根本的区别呢?
或者只是一种表示 并没有实际意义?
还说说可能会有功能上的区别 只是在2.5的版本中还没有开发呢。。。
@Resource是什么意思?
参考文档:http://www.infoq.com/cn/articles/spring-2.5-part-1
-----------------------------------------------------------------------------------------------------------------------------------------------------------------
Spring 2.5 中除了提供 @Component 注释外,还定义了几个拥有特殊语义的注释,它们分别是:@Repository、@Service 和 @Controller。在目前的 Spring 版本中,这 3 个注释和 @Component 是等效的,但是从注释类的命名上,很容易看出这 3 个注释分别和持久层、业务层和控制层(Web 层)相对应。虽然目前这 3 个注释和 @Component 相比没有什么新意,但 Spring 将在以后的版本中为它们添加特殊的功能。所以,如果 Web 应用程序采用了经典的三层分层结构的话,最好在持久层、业务层和控制层分别采用 @Repository、@Service 和 @Controller 对分层中的类进行注释,而用 @Component 对那些比较中立的类进行注释。
@Repository、@Service、@Controller则是细化
那这几个注解到底有没有功能上根本的区别呢?
或者只是一种表示 并没有实际意义?
还说说可能会有功能上的区别 只是在2.5的版本中还没有开发呢。。。
@Resource是什么意思?
参考文档:http://www.infoq.com/cn/articles/spring-2.5-part-1
-----------------------------------------------------------------------------------------------------------------------------------------------------------------
Spring 2.5 中除了提供 @Component 注释外,还定义了几个拥有特殊语义的注释,它们分别是:@Repository、@Service 和 @Controller。在目前的 Spring 版本中,这 3 个注释和 @Component 是等效的,但是从注释类的命名上,很容易看出这 3 个注释分别和持久层、业务层和控制层(Web 层)相对应。虽然目前这 3 个注释和 @Component 相比没有什么新意,但 Spring 将在以后的版本中为它们添加特殊的功能。所以,如果 Web 应用程序采用了经典的三层分层结构的话,最好在持久层、业务层和控制层分别采用 @Repository、@Service 和 @Controller 对分层中的类进行注释,而用 @Component 对那些比较中立的类进行注释。
相关文章推荐
- Spring注解@Component、@Repository、@Service、@Controller区别 .
- Spring注解@Component、@Repository、@Service、@Controller区别
- Spring注解的使用和区别:@Component、@Service、@Repository、@Controller
- Spring注解的使用和区别:@Component、@Service、@Repository、@Controller
- Spring注解的使用和区别:@Component、@Service、@Repository、@Controller
- Spring注解的使用和区别:@Component、@Service、@Repository、@Controller
- Spring注解@Component、@Repository、@Service、@Controller区别 .
- Spring注解@Component、@Repository、@Service、@Controller区别
- SpringAnnotation注解之@Component,@Repository,@Service,@Controller
- Spring注解@Component、@Repository、@Service、@Controller
- Spring注解@Component、@Repository、@Service、@Controller区别
- Spring注解@Component、@Repository、@Service、@Controller
- Spring注解@Component、@Repository、@Service、@Controller区别
- Spring注解@Component、@Repository、@Service、@Controller区别
- Spring注解@Component、@Repository、@Service、@Controller区别
- Spring注解@Component、@Repository、@Service、@Controller
- Spring注解@Component、@Repository、@Service、@Controller区别
- Spring注解@AutoWired @Component、@Repository、@Service、@Controller区别
- Spring的注解类(@Component、@Repository、@Service、@Controller )
- Spring注解@Component、@Repository、@Service、@Controller区别