<parent>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starter-parentartifactId>
<version>2.2.12.RELEASEversion>
parent>
web项目需另外添加如下依赖:
<dependency>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starter-webartifactId>
dependency>
排除自带的tomcat容器:
<dependency>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starter-webartifactId>
<exclusions>
<exclusion>
<artifactId>spring-boot-starter-tomcatartifactId>
<groupId>org.springframework.bootgroupId>
exclusion>
exclusions>
dependency>
spring-boot-starter-parent是一个springboot项目的父工程,它定义了很多当前项目的规范,比如:
a:定义了Java编译版本为 1.8.
b:使用UTF-8格式编码。
c:继承自spring-boot-dependencies,这个里面定义了依赖的版本,也是因为继承了这个依赖,我们在写依赖时才不需要写版本号。
d:执行打包操作的配置。
e:自动化的资源过滤。
f: 自动化的插件配置。
g:针对 application.properties 和application.yml 的资源过滤,包括通过profile定义不同的环境配置文件,application-dev.properties 和application-pro.properties.
Spring Boot 为 Spring MVC 提供了自动配置,并在 Spring MVC 默认功能的基础上添加了以下特性:
a:引入了 ContentNegotiatingViewResolver 和 BeanNameViewResolver(视图解析器)
b:对包括 WebJars 在内的静态资源的支持
c:自动注册 Converter、GenericConverter 和 Formatter (转换器和格式化器)
d:对 HttpMessageConverters 的支持(Spring MVC 中用于转换 HTTP 请求和响应的消息转换器)
e:自动注册 MessageCodesResolver(用于定义错误代码生成规则)
f:支持对静态首页(index.html)的访问
g:自动使用 ConfigurableWebBindingInitializer
<Context docBase="xxx" path="/xxx" reloadable="true"/>
<Context docBase="xxx" path="/xxx" autoDeploy="true"/>
第一步:添加依赖
<dependency>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-devtoolsartifactId>
<optional>trueoptional>
<scope>truescope>
dependency>
<plugin>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-maven-pluginartifactId>
<configuration>
<fork>truefork>
configuration>
plugin>
第二步:application.yml配置文件中添加配置
---
spring:
devtools:
restart:
#热部署生效
enabled: true
#设置重启的目录
#additional-paths: src/main/java
#classpath目录下的WEB-INF文件夹内容修改不重启
exclude: WEB-INF/*
第三步:eclipse或者其他IDE设置“自动编译”