本文包括:html
1. springboot 基本pom.xml配置
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <!--项目或者组织的惟一标志--> <groupId>wqz.zoom</groupId> <!--项目名--> <artifactId>springbootdemo</artifactId> <version>0.0.1-SNAPSHOT</version> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.0.4.RELEASE</version> <relativePath></relativePath> </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <fork>true</fork> </configuration> </plugin> </plugins> </build> </project>
须要不一样的开发方向,按照下方jar包介绍,添加依赖便可 java
springboot 依赖包详解:
转自 https://blog.csdn.net/chen15369337607/article/details/78445773web

<?xmlversion="1.0"encoding="UTF-8"?><projectxmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>com.zlc</groupId><artifactId>demo</artifactId><version>0.0.1-SNAPSHOT</version><packaging>jar</packaging><name>demo</name><description>demoprojectforSpringBoot</description><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>1.5.3.RELEASE</version><relativePath/><!--lookupparentfromrepository--></parent><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding><java.version>1.8</java.version></properties><dependencies><!--从父依赖那继承版本号--><!--生产准备的特性,用于帮你监控和管理应用--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-actuator</artifactId></dependency><!--对高级消息队列协议的支持,经过SpringBoot-rabbit实现--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-amqp</artifactId></dependency><!--对面向切面变成的支持,经过spring-aop和AspectJ--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-aop</artifactId></dependency><!--对Springbatch的支持,包括HSQLDB数据库--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-batch</artifactId></dependency><!--对MongoDBNOSQL数据库的支持,包括spring-data-mongodb--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-mongodb</artifactId></dependency><!--经过对REST暴露Springdata仓库的支持,经过Spring-data-rest-webmvc实现--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-rest</artifactId></dependency><!--对java持久化API的支持,包括Spring-data-jpa,spring-orm和Hibernate--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-solr</artifactId></dependency><!--对FreeMarker模板引擎的支持--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-freemarker</artifactId></dependency><!--对基于HATEOAS的RESTful服务的支持,经过Spring-hateoas;--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-hateoas</artifactId></dependency><!--对普通Spring-integration模块的支持--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-integration</artifactId></dependency><!--对JDBC数据库的支持--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-jdbc</artifactId></dependency><!--对JerseyRESTfulWeb服务框架的支持--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-jersey</artifactId></dependency><!--对JTA分布式事务的支持,经过Atomikos--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-jta-atomikos</artifactId></dependency><!--对JTA分布式事务的支持,经过Bitronix实现--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-jta-bitronix</artifactId></dependency><!--对javax.mail的支持--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-mail</artifactId></dependency><!--对spring-mobile的支持--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-mobile</artifactId></dependency><!--对spring-security模板引擎的支持--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-security</artifactId></dependency><!--对spring-social-facebook的支持--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-social-facebook</artifactId></dependency><!--对spring-social-twitter的支持--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-social-twitter</artifactId></dependency><!--对经常使用测试依赖的支持,包括JUnit,Hamcrest和Mockito还有Spring-test模块;--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId></dependency><!--对Thymeleaf模板引擎的支持,包括和Spring的集成;--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-thymeleaf</artifactId></dependency><!--对全栈web开发的支持,包括Tomcat和spring-webmvc;--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><!--对websocket开发的支持--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-websocket</artifactId></dependency><!--导入JettyHTTP引擎(做为Tomcat的代替)--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-jetty</artifactId></dependency><!--导入SpringBoot的默认日志系统(Logback)--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-logging</artifactId></dependency><!--导入SpringBoot的默认HTTP引擎(Tomcat)--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-tomcat</artifactId></dependency><!--导入UndertowHTTP引擎(做为tomcat的代替)--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-undertow</artifactId></dependency><!--对GemFire分布式数据存储的支持,包括spring-data-gemfire--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-gemfire</artifactId></dependency><!--对java持久化API的支持,包括Spring-data-jpa,spring-orm和Hibernate--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-jpa</artifactId></dependency></dependencies><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><configuration><fork>true</fork><source>1.8</source><target>1.8</target></configuration></plugin></plugins></build></project>原文:https://blog.csdn.net/chen15369337607/article/details/78445773
maven配置详解:
转自 http://www.javashuo.com/article/p-ckzkvhfg-gz.htmlspring

2. 配置devtools实现热部署
devtools的原理mongodb
深层原理是使用了两个ClassLoader,一个Classloader加载那些不会改变的类(第三方Jar包),另外一个ClassLoader加载会更改的类,称为restart ClassLoader,这样在有代码更改的时候,原来的restart ClassLoader 被丢弃,从新建立一个restart ClassLoader,因为须要加载的类相比较少,因此实现了较快的重启时间。数据库
使用须要添加如下的配置:apache
<dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <optional>true</optional> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <fork>true</fork> <!-- 此处必须配置,不然 devtools 不会生效--> </configuration> </plugin> </plugins> </build>
说明:浏览器
(1) devtools能够实现页面热部署(即页面修改后会当即生效,这个能够直接在application.properties文件中配置spring.thymeleaf.cache=false来实现),
实现类文件热部署(类文件修改后不会当即生效),实现对属性文件的热部署。
即devtools会监听classpath下的文件变更,而且会当即重启应用(发生在保存时机),注意:由于其采用的虚拟机机制,该项重启是很快的
(2)配置了true后在修改java文件后也就支持了热启动,不过这种方式是属于项目重启(速度比较快的项目重启),会清空session中的值,也就是若是有用户登录的话,项目重启后须要从新登录。tomcat
默认状况下,/META-INF/maven,/META-INF/resources,/resources,/static,/templates,/public这些文件夹下的文件修改不会使应用重启,可是会从新加载(devtools内嵌了一个LiveReload server,当资源发生改变时,浏览器刷新)。springboot
devtools的配置
在application.properties中配置spring.devtools.restart.enabled=false,此时restart类加载器还会初始化,但不会监视文件更新。
在SprintApplication.run以前调用System.setProperty(“spring.devtools.restart.enabled”, “false”);能够彻底关闭重启支持,配置内容:
#热部署生效 spring.devtools.restart.enabled: true #设置重启的目录 #spring.devtools.restart.additional-paths: src/main/java #classpath目录下的WEB-INF文件夹内容修改不重启 spring.devtools.restart.exclude: WEB-INF/**
IDEA配置
当咱们修改了Java类后,IDEA默认是不自动编译的,而spring-boot-devtools又是监测classpath下的文件发生变化才会重启应用,因此须要设置IDEA的自动编译:
(1)File-Settings-Compiler-Build Project automatically
(2)ctrl + shift + alt + /,选择Registry,勾上 Compiler autoMake allow when app running
测试
- 修改类–>保存:应用会重启
- 修改配置文件–>保存:应用会重启
- 修改页面–>保存:应用不会重启,但会从新加载,页面会刷新(原理是将spring.thymeleaf.cache设为false,参考:Spring Boot配置模板引擎)