`
Tristan_S
  • 浏览: 373030 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

Spring注解@Component、@Repository、@Service、@Controller区别

    博客分类:
  • jj
 
阅读更多
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区别.doc

    Spring 注解@Component、@Repository、@Service、@Controller 区别 在 Spring 框架中,@Component、@Repository、@Service、@Controller 是四个常用的注解,它们都是继承自 @Component 注解,用于标注不同的组件或 ...

    Spring注解 @Component、@Repository、@Service、@Controller区别

    ### Spring注解 @Component、@Repository、@Service、@Controller 的区别 #### 一、引言 在现代软件开发中,尤其是Java领域的企业级应用开发中,Spring框架因其灵活、强大的依赖注入(DI)和面向切面编程(AOP)...

    解释@Component @Controller @Service @Repository

    本篇文章将深入探讨四个关键的注解:`@Component`、`@Controller`、`@Service`和`@Repository`,它们是Spring框架中的核心注解,用于定义不同层次的组件。 首先,`@Component`注解是最基础的,它代表了一个通用的...

    Spring Boot技术知识点:如何深入理解@Component注解

    在Spring Boot中,通过`@SpringBootApplication`注解,Spring会默认进行组件扫描,寻找类路径下标记了`@Component`、`@Service`、`@Repository`和`@Controller`的类。这些注解都是`@Component`的特殊形式,分别对应...

    spring注解笔记

    在本节中,我们主要介绍几个Spring中常用的注解,它们分别是@Component、@Controller、@Service和@Repository,这些注解用于将Java类声明为Spring管理的Bean。 #### 2. @Component注解 @Component是一个通用的构...

    Spring注解 - 52注解 - 原稿笔记

    在火狐中显示可能会有问题,大家都是... @RequestMapping , @RequestParam , @Resource , @ResponseBody , @RestController , @Scope , @Service , @Validated , @Value , @WebFilter , @WebInitParam , @WebListener

    spring @Component注解原理解析

    在 Spring 框架中,@Component 注解有多种衍生注解,如 @Controller、@Service、@Repository 等,这些注解都是 @Component 注解的子集,它们分别用于标注控制器、业务层和数据访问层的 Bean。 在使用 @Component ...

    Spring @compenent注解详解

    这个注解及其派生注解(如`@Service`、`@Repository`和`@Controller`)是Spring依赖注入(Dependency Injection, DI)机制的基础。在这篇文章中,我们将深入探讨`@Component`注解的各个方面,以及如何在实际应用中...

    Spring @讲义.txt

    ### Spring 注解详解:@Component、@Repository、@Service、@Controller 区别 #### 一、Spring 注解概述 Spring 框架是 Java 开发领域中非常流行的一个轻量级框架,它通过依赖注入(DI)和面向切面编程(AOP)等...

    spring使用注解暴露remoting服务

    在Spring配置中,我们通常使用@ComponentScan注解来指定需要扫描的包,这样Spring会自动找到带有@Service、@Repository和@Component注解的类。 ```java @Configuration @ComponentScan(basePackages = {...

    spring3.x注解

    在 Spring 3.x 中,提供了多种用于类注册的注解,如 @Component、@Repository、@Service、@Controller 等。 1. @Component @Component 注解是所有受 Spring 管理组件的通用形式,默认的名称(id)是小写开头的非...

    Spring @Bean vs @Service注解区别

    最后,需要强调的是,@Bean和@Service只是Spring框架中的两个组件扫描注解,还有其他许多注解,例如@Controller、@Repository、@Component等。每个注解都有其特定的用途和使用场景,需要根据实际情况选择合适的注解...

    spring @component的作用详细介绍

    在Spring框架中,@Component及其衍生的注解@Controller、@Service、@Repository是用于实现自动化的依赖注入与组件扫描,这是Spring框架的核心功能之一,让开发者能够以声明式的方式管理Java对象的生命周期,并且将...

    spring注解实例

    常见的注解包括@Component、@Service、@Repository和@Controller,它们用于声明组件,分别对应通用、服务、数据访问和Web层。此外,@Autowired注解用于自动装配bean,@Qualifier注解用于指定特定的bean。 **2. @...

    spring注解属性的用法

    Spring提供了几个`@Component`的派生注解,如`@Service`、`@Repository`和`@Controller`,它们在功能上与`@Component`相同,但提供了语义上的区别,方便代码管理和阅读。 - `@Service`:通常用于业务逻辑层...

    浅谈spring 常用注解

    在Spring中,@Component、@Repository、@Service、@Controller等注解都是用来定义Bean的,它们之间的区别在于标识组件的类型。 * @Component:是一个基本的注解,用于标识普通的Java类。 * @Repository:用于标识...

    对Spring中注解怎么实现的一些基本原理

    在Spring中,常见的注解如`@Autowired`、`@Component`、`@Service`、`@Repository`和`@Controller`等,用于标记类、方法或字段,以便Spring容器进行自动配置和管理。 **注解的处理过程:** 1. **扫描和发现**:...

    Struts2+spring注解配置简介

    Spring提供了如@Component、@Service、@Repository和@Controller等注解,用于标记Java类作为Spring容器中的bean。例如,@Component可以用来定义一个基础组件,@Service通常用于业务逻辑层,@Repository用于数据访问...

    Spring 注解 小例子

    1. `@Component`、`@Service`、`@Repository` 和 `@Controller` 这些注解是Spring组件扫描的基础,它们定义了一个bean。`@Component`是最通用的,适用于任何类型的服务。`@Service`通常用于业务逻辑层,`@...

    最简单的一个spring注解实例

    1. **@Component** 注解:这是所有Spring组件注解的基础,如 @Service、@Repository 和 @Controller。在最简单的情况下,我们可以在一个类上使用 @Component 注解来告诉Spring容器,这个类是一个需要管理的bean。...

Global site tag (gtag.js) - Google Analytics