@SpringBootApplication 等同@SpringBootConfiguration@EnableAutoConfiguration@ComponentScan
@Configuration加入了这个注解的类被认为是 Spring Boot 的配置类
@Bean这个注解是方法级别上的注解,主要添加在 @Configuration 或 @SpringBootConfiguration 注解的类,有时也可以添加在 Component 注解的类。它的作用是定义一个Bean。
@Value
通常情况下,我们需要定义一些全局变量,都会想到的方法是定义一个 public static 变量,在需要时调用,是否有其他更好的方案呢?答案是肯定的。下面请看代码:
@Value("${server.port}")
String port;
@RequestMapping("/hello")
public String home(String name) {
return "hi "+name+",i am from port:" +port;
}
其中,server.port 就是我们在 application.yml 里面定义的属性,
@EnableScheduling // 开启Quartz
@EnableCaching // 开启缓存
@EnableRetry // 开启重试
@EnableTransactionManagement // 开始事务
@MapperScan(“org.kanpiaoxue.dao”) // 开启MyBatis的DAO扫描
@GetMapping 组合注解,是@RequestMapping(method = RequestMethod.GET)的缩写
@PostMapping 组合注解,是@RequestMapping(method = RequestMethod.POST)的缩写