spring-boot个人总结(1)

来源:互联网 发布:淘宝上面什么比较好卖 编辑:程序博客网 时间:2024/05/16 11:06

spring-boot配置步骤
1:maven项目的pom文件中引入parent
spring-boot-starter-parent
2:maven项目的pom文件中引入以下依赖
spring-boot-starter-web
spring-boot-starter-actuator
3:启动spring-boot所需要的插件



spring-boot-maven-plugin 1.3.5.RELEASE
com.gtja.Application




repackage






4:spring-boot启动代码书写
@SpringBootApplication
@EnableConfigurationProperties({ExpertStockConsumerConfig.class,ExpertStockProducerConfig.class,
PrepayConsumerConfig.class, ToSingleProducerConfig.class, GeTuiInfoConfig.class, XGYYConsumerConfig.class})
@ComponentScan
@EnableAutoConfiguration
public class Application {
public static void main(String[] args){
SpringApplication springApplication = new SpringApplication(Application.class);
springApplication.run(args);

}

}
spring-boot注解
@SpringBootApplication:该注解默认代替EnableConfiguratorProperties CompentScan EnableAutoConfiguration这三个注解,一般都在main方法上使用
@EnableConfigurationProperties:属性注入,也就是说自定义实体类上注入ConfigurationProperties(prefix=”“)
当Application.run()方法启动项目时,自动加载类 配置文件 如果配合@Beans一起使用时,等同于将该类添加到bean中的过程
@CompentScan:可以让我们自由的使用任何标准的spring框架去定义beans和注入依赖,springIOC和DI很好的体现,spring注解都可以使用 如:Autowired Resources
@EnableAutoConfiguration:这个注解告诉spring-boot根据添加的jar依赖猜测你想如何配置spring
由于我们工程中添加了spring-boot-starter-web的jar包 ,而该包中添加了Tomcat和Springmvc的依赖
所以自动对spring进行设置,我们无需在pom文件中引入tomcat和spring相关的依赖
@RestController:构造型注解,不是spring-boot特有的 一般搭配RequestMapping一起使用
@Component:被用在自动扫描和装配的类上
@Beans:主要被用在方法上面

原创粉丝点击