一句话说明springboot常用注解!

1.配置

@SpringBootApplication springboot启动,本质上是@ComponentScan、@Configuration和@EnableAutoConfiguration三个注解的组合

@SpringBootConfiguration springboot启动配置

@Configuration 配置注解

@EnableAutoConfiguration 自动配置

@Component 组件,配置在类上

@ComponentScan 组件扫描

@Controller 组件,放在controller层

@Bean 向容器内注入对象和@Configuration配合使用

@Service 组件,放在service层

@Repository 组件,用于dao层

@Import 导入其他配置类

@ImportResource 用于导入xml配置

@Autowired 自动注入,按类型装配

@Inject 没有required(是否必须赋值成功)的@Autowired

@Qualifier 按名称装配,常和@Autowired搭配使用

@Resource javaee的按名称装配

@Value 读取配置文件的字段值

2.mvc

@ResponseBody 不进行视图解析,直接返回流,常用于返回xml和json

@RestController @Controller +@ResponseBody

@RequestMapping 请求地址映射

@RequestParam 用于请求参数映射

@PathVariable 用于restful风格的参数映射

3.其他

@Async 异步调用

@ControllerAdvice 统一处理异常

@ExceptionHandler(Exception.class) @ControllerAdvice捕捉到以后执行的方法

@Conditional 满足指定条件时开启配置

@ConditionalOnBean 当容器中有指定的 Bean 才开启配置

@ConditionalOnMissingBean 当容器中没有指定的 Bean 才开启配置

@ConditionalOnClass 当容器中有指定的 Class 才开启配置。

@ConditionalOnMissingClass 当容器中没有指定的 Class 才开启配置。

猜你喜欢

转载自blog.csdn.net/qq_39404258/article/details/107918769