下面来说说springBoot项目的devtools自动部署:
SpringBoot的部署分为两种,一个是HTML页面的不重启项目自动编译,,一个是JAVA代码的热部署
1.项目搭建
1.1 UserDAO.cs
package com.example.demo; import org.springframework.stereotype.Repository; @Repository public class UserDAO { public void AddUser() { System.out.print("开始AddU"); } }
1.2 UserService.cs
package com.example.demo; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @Service public class UserService { @Autowired private UserDAO userDAO; public void AddUser() { this.userDAO.AddUser(); } }
1.3 UserController.cs
package com.example.demo; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; @Controller public class UserController { @RequestMapping("/User") public String User(){ System.out.print("开始"); return "index"; } }
1.4 index.html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>部署</title> </head> <body> <span >devtools</span> </body> </html>
项目搭建完成 运行结果
2.项目代码配置
2.1pom.xml配置文件
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <optional>true</optional> </dependency> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <version>1.5.3.RELEASE</version> <configuration> <fork>true</fork> <!-- 如果没有该配置,devtools不会生效 --> </configuration> <dependencies> </dependencies> </plugin> </plugins> </build>
2.2 application.properties
#开启或者关闭freemarker和thymeleaf的页面缓存 spring.freemarker.cache=false spring.thymeleaf.cache=true spring.devtools.restart.enabled=true #需要开启热部署的文件目录 spring.devtools.restart.additional-paths=src/main/java #使用了mybatis好像需要设置,应该没有必要。且生产环境需要移除 #restart.include.mapper=/mapper-[\\w-\\.]+jar #restart.include.pagehelper=/pagehelper-[\\w-\\.]+jar #静态文件下不需要重启 #spring.devtools.restart.exclude=static/**,public/** spring.devtools.restart.exclude=templates/*
3.IDEA配置
3.1 File-Settings-Compiler-Build project automatically
3
3.2ctrl + shift + alt + /,选择Registry,勾上 Compiler autoMake allow when app running
4.测试index.html 加123
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>部署</title> </head> <body> <span >devtools123</span> </body> </html>
直接访问页面结果