sb-所有的注解

@SpringBootApplication
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication 被 @Configuration、@EnableAutoConfiguration、@ComponentScan 注解所修饰,换言之 Springboot 提供了统一的注解来替代以上三个注解,简化程序的配置。

@Configuration用于配置,等同于读取xml配置文件。
@EnableAutoConfiguration是把容器中bean对象自动装配在一起。框架替代了xml中手工维护bean之间的依赖关系。
@ComponentScan扫描所有被注解的类,然后创建对象保存到容器中。

这三个功能是项目启动的必须项,一个注解搞定。
必看:https://blog.csdn.net/claram/article/details/75125749


@RestController和@RequestMapping(“hello”)
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestMapping;

必看:https://blog.csdn.net/u010412719/article/details/69710480


@Bean:是一个方法级别上的注解,主要用在@Configuration注解的类里,也可以用在@Component注解的类里。添加的bean的id为方法名。必看:https://www.cnblogs.com/feiyu127/p/7700090.html


@EnableSwagger2:启用Swagger2


@ConditionalOnExpression:springboot中@ConditionalOnExpression注解,在特定情况下使用相关配置或者实例化bean。通过在配置文件中增加application.profile项,确定是线下环境还是线上环境。如果是线上环境,则自动关闭swagger,避免了线上暴露接口。必看:https://blog.csdn.net/Winter_chen001/article/details/80391413


猜你喜欢

转载自blog.csdn.net/yulong1026/article/details/80545830