提示信息

spring boot 都有哪些注解?

枝头散尽 已关注

Spring Boot提供了许多注解来简化Spring应用程序的配置和开发。以下是一些最常见的Spring Boot注解:

  1. @SpringBootApplication: 这是一个方便的注解,它包括了@Configuration@EnableAutoConfiguration@ComponentScan注解。

  2. @Configuration: 标记一个类为Spring的Java配置类。

  3. @EnableAutoConfiguration: 告诉Spring Boot根据添加的依赖自动配置你的Spring应用程序。

  4. @ComponentScan: 它默认扫描与配置类相同的包以寻找Spring组件。

  5. @RestController: 这是一个特殊类型的@Controller,它包含@ResponseBody意味着返回值直接写入到HTTP response body中。

  6. @RequestMapping 和 HTTP方法注解 (@GetMapping, @PostMapping 等): 用于配置具体的控制器方法的路由。

  7. @Autowired: 自动装配bean。

  8. @Service, @Repository, @Controller, @Component: 这些是Stereotype注解,用于标记Spring组件。

  9. @Bean: 表示一个方法产生一个由Spring管理的bean。

  10. @Value: 用于注入从属性文件中读取的值。

  11. @Profile: 指定某个bean只在某个或某些特定的profile下才会创建。

  12. @PropertySource: 用于声明属性资源位置。

这些只是其中的一部分,Spring Boot还有许多其他注解。你应该根据你的具体需求去选择和使用它们。

枝头散尽 关注 已关注

最近一次登录:2023-09-26 15:17:22   

暂时还没有签名,请关注我或评论我的文章
×
分享到朋友圈