01.springboot入门,idea创建springboot项目
一.Springboot介绍使用 :
遵循约定优于配置的原则,以精简配置降低开发成本为目的,简化配置spring
作用:
简化编码
简化配置
简化部署
Spring Boot到底有多么精简呢?
1.使用Spring Boot快速搭建Spring框架,并在前台页面输出“Hello Spring Boot”
查看pom,查看依赖:
默认配置好了tomcat
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<!--排除掉默认tomcat配置 -->
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
启动类: 项目名称+Application
特点:自动创建
作用: 启动项目,启动配置
@SpringBootConfiguration :
@EnableAutoConfiguration:启动自动配置,配置spring相关固定的配置
@ComponentScan:对项目里面的所有注解进行扫描,比如@Controller
创建一个类
@Spring4.0以后提供@RestController 将来 返回的数据都是添加到ResponseBody,可以省略@ResponseBody
启动:
二.Springboot的配置文件
1.application.properties
2.application.yml
第三.使用config.properties文件配置
快速部署 1.项目中添加插件,使用maven构建jar包
1 <build>
2 <plugins>
3 <!‐‐构建SpringBoot时自动生成主清单属性‐‐>
4 <plugin>
5 <groupId>org.springframework.boot</groupId>
6 <artifactId>spring‐boot‐maven‐plugin</artifactId>
7 </plugin>
8 </plugins>
9 </build>
2.运行maven install,构建jar包 3.使用java命令运行jar包(java -jar jt77-1.0-SNAPSHOT.jar)
Spring Boot+IDEA热部署:
1.加入依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>springloaded</artifactId>
<version>1.2.5.RELEASE</version>
</dependency>
2.DevTools生效
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<fork>true</fork>
</configuration>
</plugin>
3.启用自动构建项目
File > Settings>Build,Execution,Deplyment>Compiler
Build project automatically
4.启用在项目运行时,允许项目编译
“Ctrl + Shift + Alt + /”> Registry
compiler.automake.allow.when.app.running