#此处总结几个常用注解,其他注解遇到了再补充:
- @Configuration:类上,表明这是一个IOC容器,相当于springMVC中的配置文件,springboot使用该注解用作java配置。
- @Bean: 方法上,常结合@Configuration使用,往spring容器中添加一个组件。
- @Component: 类上,将备被注解的类交给spring容器管理,例如本章的 CustomProperties类 。
- @ComponentScan:类上,相当于 xml配置文件中的context:component-scan标签,对标注了@Controller、@Service、@Respoitory、@Component等的类扫描,注册为bean。
- @SpringBootConfiguration:启动类上,包含@SpringBootConfiguration(继承@Configuration)、 @EnableAutoConfiguration和 @ComponentScan注解。
- @RestController:包含@ResponseBody 和 @Controller 的注解。
- @PathVariable、@RequestParam、@RequestMapping、@Controller、@Service、@RequestBody、@ResponseBody:跟SpringMVC相同。
请求路径 PUT、DELETE、PATCH 同下
- @GetMapping = @RequestMapping(method = RequestMethod.GET)。
- @PostMapping = @RequestMapping(method = RequestMethod.POST)。
- @EnableScheduling:建议加到启动类上,开启springboot定时支持,结合@Scheduled做定时任务。
- @PropertySource:加载指定的配置文件,例如本章中附加:自定义配置文件