spring boot 都有哪些注解?
Spring Boot提供了许多注解来简化Spring应用程序的配置和开发。以下是一些最常见的Spring Boot注解:
@SpringBootApplication
: 这是一个方便的注解,它包括了@Configuration
、@EnableAutoConfiguration
和@ComponentScan
注解。@Configuration
: 标记一个类为Spring的Java配置类。@EnableAutoConfiguration
: 告诉Spring Boot根据添加的依赖自动配置你的Spring应用程序。@ComponentScan
: 它默认扫描与配置类相同的包以寻找Spring组件。@RestController
: 这是一个特殊类型的@Controller,它包含@ResponseBody意味着返回值直接写入到HTTP response body中。@RequestMapping
和 HTTP方法注解 (@GetMapping
,@PostMapping
等): 用于配置具体的控制器方法的路由。@Autowired
: 自动装配bean。@Service
,@Repository
,@Controller
,@Component
: 这些是Stereotype注解,用于标记Spring组件。@Bean
: 表示一个方法产生一个由Spring管理的bean。@Value
: 用于注入从属性文件中读取的值。@Profile
: 指定某个bean只在某个或某些特定的profile下才会创建。@PropertySource
: 用于声明属性资源位置。
这些只是其中的一部分,Spring Boot还有许多其他注解。你应该根据你的具体需求去选择和使用它们。