Spring Boot常用注解

  1. @SpringBootApplication
    用于标识主应用程序类,通常位于项目的顶级包中。
    这个注解包含了@Configuration、@EnableAutoConfiguration 和 @ComponentScan

  2. @Controller
    用于标识类作为 Spring MVC 的Controller

  3. @RequestController
    类似于@Controller, 但它是专门用于RESTful Web服务的,它包含了@Controller和@ResponseBody

  4. @RequestMapping
    用于将http请求映射到Controller的处理方法。
    可以用在类级别和方法级别。

  5. @Autowired
    用于自动注入Spring 容器中的 Bean,可以用在构造方法、字段、Setter方法上

  6. @Service
    用于标识类作为服务层的 Bean

  7. @Repository
    用于标识类作为数据访问层的Bean, 通常用于与数据库交互

  8. @Component
    通用的组件主键,用于标识任何Spring 托管的 Bean

  9. @Configuration
    用于定义配置类,类中可能包含一些@Bean 注解用于定义 Bean

  10. @EnableAutoConfiguration
    用于启用Spring Boot的自动配置机制,根据项目的依赖和配置自动配置 Spring 应用程序。

  11. @Value
    用于从属性文件或配置中读取值,将值注入到成员变量中。

  12. @Qualifier
    与@Autowired 一起使用,指定注入时使用的 Bean名称。

  13. @ConfigurationProperties
    用于将配置文件中的属性映射到 Java Bean

  14. @Profile
    用于定义不同环境下的配置,可以标识在类或方法上

  15. @Async
    用于将方法标记为异步执行

posted @ 2025-04-30 17:20  kuki'  阅读(18)  评论(0)    收藏  举报