/imooc-springboot-starter/src/main/resources/application.properties

#关闭缓存,  即时刷新
#spring.freemarker.cache=false
spring.thymeleaf.cache=true #热部署生效
spring.devtools.restart.enabled=true
#设置重启的目录,添加那个目录的文件需要restart
spring.devtools.restart.additional-paths=src/main/java
# 为mybatis设置, 生产环境可删除
#restart.include.mapper=/mapper-[\\w-\\.]+jar
#restart.include.pagehelper=/pagehelper-[\\w-\\.]+jar
#排除那个目录的文件不需要restart
spring.devtools.restart.exclude=static/**,public/**,WEB-INF/**
#classpath目录下的WEB-INF文件夹内容修改不重启
#spring.devtools.restart.exclude=WEB-INF/**

/imooc-springboot-starter/pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<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>com.imooc</groupId>
<artifactId>imooc-springboot-starter</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging> <name>imooc-springboot-starter</name>
<description>Demo project for Spring Boot</description> <parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.6.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</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</artifactId>
</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>
<!-- 热部署 -->
<!-- devtools可以实现页面热部署(即页面修改后会立即生效,
这个可以直接在application.properties文件中配置spring.thymeleaf.cache=false来实现) -->
<!-- 实现类文件热部署(类文件修改后不会立即生效),实现对属性文件的热部署。 -->
<!-- 即devtools会监听classpath下的文件变动,并且会立即重启应用(发生在保存时机),
注意:因为其采用的虚拟机机制,该项重启是很快的 -->
<!-- (1)base classloader (Base类加载器):加载不改变的Class,例如:第三方提供的jar包。 -->
<!-- (2)restart classloader(Restart类加载器):加载正在开发的Class。 -->
<!-- 为什么重启很快,因为重启的时候只是加载了在开发的Class,没有重新加载第三方的jar包。 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
<!-- optional=true, 依赖不会传递, 该项目依赖devtools;
之后依赖boot项目的项目如果想要使用devtools, 需要重新引入 -->
</dependency>
</dependencies> <build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build> </project>

/imooc-springboot-starter/src/main/java/com/imooc/controller/UserController.java

package com.imooc.controller;

import java.util.Date;

//import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController; import com.imooc.pojo.LeeJSONResult;
import com.imooc.pojo.User; //@Controller
@RestController // @RestControler = @Controller + @ResponseBody
@RequestMapping("/user")
public class UserController { //@RequestMapping("/hello")
@RequestMapping("/getUser")
//@ResponseBody
public User hello() {
//public User getUser() {
User u = new User();
u.setName("imooc");
u.setAge(18);
u.setBirthday(new Date());
u.setPassword("imooc");
//u.setDesc(null);
u.setDesc("hello imooc~~"); return u; }
@RequestMapping("/getUserJson")
//@ResponseBody
public LeeJSONResult hello1() {
//public LeeJsonResult getUserJson() {
User u = new User();
//u.setName("imooc");
u.setName("imooc1");
u.setAge(18);
u.setBirthday(new Date());
u.setPassword("imooc");
//u.setDesc(null);
//u.setDesc("hello imooc~~");
u.setDesc("hello imooc1~~"); return LeeJSONResult.ok(u); }
}

/imooc-springboot-starter/src/main/java/com/imooc/controller/UserController.java

package com.imooc.controller;

import java.util.Date;

//import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController; import com.imooc.pojo.LeeJSONResult;
import com.imooc.pojo.User; //@Controller
@RestController // @RestControler = @Controller + @ResponseBody
@RequestMapping("/user")
public class UserController { //@RequestMapping("/hello")
@RequestMapping("/getUser")
//@ResponseBody
public User hello() {
//public User getUser() {
User u = new User();
//u.setName("imooc");
u.setName("imooc1");
u.setAge(18);
u.setBirthday(new Date());
//u.setPassword("imooc");
u.setPassword("imooc1");
//u.setDesc(null);
//u.setDesc("hello imooc~~");
u.setDesc("hello imooc1~~"); return u; }
@RequestMapping("/getUserJson")
//@ResponseBody
public LeeJSONResult hello1() {
//public LeeJsonResult getUserJson() {
User u = new User();
//u.setName("imooc");
u.setName("imooc1");
u.setAge(18);
u.setBirthday(new Date());
u.setPassword("imooc");
//u.setDesc(null);
//u.setDesc("hello imooc~~");
u.setDesc("hello imooc1~~"); return LeeJSONResult.ok(u); }
}

第4章 springboot热部署 4-1 SpringBoot 使用devtools进行热部署的更多相关文章

  1. (40). springboot + devtools(热部署)【从零开始学Spring Boot】

    我们之前在在()Spring Boot热部署[从零开始学Spring Boot] (http://412887952-qq-com.iteye.com/blog/2291518 )讲过通过使用spri ...

  2. SpringBoot基础学习(一) SpringBoot概念、简单案例实现、单元测试及热部署讲解

    SpringBoot概念 Spring优缺点分析 Spring优点 Spring是Java企业版(Java Enterprise Edition,JEE,也称J2EE)的轻量级代替品,无需开发重量级的 ...

  3. 【SpringBoot】单元测试进阶实战、自定义异常处理、t部署war项目到tomcat9和启动原理讲解

    ========================4.Springboot2.0单元测试进阶实战和自定义异常处理 ============================== 1.@SpringBoot ...

  4. 关于springboot项目的jar和war两种打包方式部署的区别

    关于springboot项目的jar和war两种打包方式部署的区别 关于springboot项目的jar和war两种打包方式部署的区别? https://bbs.csdn.net/topics/392 ...

  5. 在同一个tomcat下部署多个springboot项目时,springboot项目无法正常启动的问题

    这个问题是基于,不使用springboot内置的tomcat会产生(即使用自己的tomcat时). 今天在部署springboot项目的时候遇到了一个问题,怎么部署都访问不了,在网上查了很多原因,什么 ...

  6. 手把手教你实现热更新功能,带你了解 Arthas 热更新背后的原理

    文章来源:https://studyidea.cn/java-hotswap 一.前言 一天下午正在摸鱼的时候,测试小姐姐走了过来求助,说是需要改动测试环境 mock 应用.但是这个应用一时半会又找不 ...

  7. 深入探索Android热修复技术原理读书笔记 —— so库热修复技术

    热修复系列文章: 深入探索Android热修复技术原理读书笔记 -- 热修复技术介绍 深入探索Android热修复技术原理读书笔记 -- 代码热修复技术 深入探索Android热修复技术原理读书笔记 ...

  8. Ionic APP 热更新 之 产品发布状态下的热更新搭建,去local-dev-addon插件

    上一篇,我们介绍了在本地开发环境下的ionic项目热更新测试, 本文,我们将详细说明如何在去掉cordova-hot-code-push-local-dev-addon插件的情况下,实现热更新. 使用 ...

  9. springboot(十一)-为什么要用springboot

    前言 学习了一段时间springboot,一般都可以在项目中使用springboot开发了.因为springboot的东西并不多,或者说,springboot根本就没有新东西. 好了,现在问一句,我们 ...

  10. springboot学习笔记:9.springboot+mybatis+通用mapper+多数据源

    本文承接上一篇文章:springboot学习笔记:8. springboot+druid+mysql+mybatis+通用mapper+pagehelper+mybatis-generator+fre ...

随机推荐

  1. ADO.NET实体框架Entity Framework模型-基于XML解析

            最近由于项目需求,需要对实体框架内表之间的关系进行处理,主要功能要求是通过一表名,返回其在实体框架内的所有关系表.主外键及每个字段的属性.先简单描述我解决这个问题从开始到最后的分析实现 ...

  2. 05-THREE.JS 产生大雾的效果

    <!DOCTYPE html> <html> <head> <title></title> <script src="htt ...

  3. 22 Python 模块与包

    一 模块 1 什么是模块? 常见的场景:一个模块就是一个包含了python定义和声明的文件,文件名就是模块名字加上.py的后缀. 但其实import加载的模块分为四个通用类别: 1 使用python编 ...

  4. L124

    I have a toothache because there is a cavity in one of my teeth. I founded an orphanage last year an ...

  5. UVA - 11768 Lattice Point or Not (扩展欧几里得)

    求一条线段上有多少个整点. 是道扩欧基础题,列出两点式方程,然后分四种情况讨论即可.但细节处理较多很容易写挫(某zzWA了十几发才过掉的). 由于数据精度较小,浮点数比较没有用eps,直接==比较了. ...

  6. CodeForces - 650D:Zip-line (LIS & DP)

    Vasya has decided to build a zip-line on trees of a nearby forest. He wants the line to be as long a ...

  7. loj 6083.「美团 CodeM 资格赛」数码

    题目: 给定两个整数\(l\)和\(r\),对于任意\(x\),满足\(l\leq x\leq r\),把\(x\)所有约数写下来. 对于每个写下来的数,只保留最高位的那个数码.求\([1,9]\)中 ...

  8. 51nod1680 区间求和

    有n个数,给定一个k,求所有长度大于等于k的区间中前k大数的总和.这样就比较简单相信大家都会,所以此题要求当k=1~n的总和,即求 ∑nk=1∑n−k+1i=1∑nj=i+k−1  区间前K大和 In ...

  9. 使用sort&awk实现文件内容块排序

    源文件为: [root@luo5 wangxx]# cat -v luo.txt J LuoSoutth jfsaNanjing,china Y ZhangVictory UniversityNejf ...

  10. hw_module_t 加载过程

    每一个HAL模块都有一个ID值,以这些ID值为参数来调用硬件抽象层提供的函数hw_get_module就可以将指定的模块加载到内存来,并且获得 一个hw_module_t接口来打开相应的设备. 函数h ...