當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
SpringBoot热部署之devtools案例(学习笔记)
生活随笔
收集整理的這篇文章主要介紹了
SpringBoot热部署之devtools案例(学习笔记)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
聲明:本案例學習http://blog.csdn.net/je_ge,在此感謝je_ge提供的學習用的資料
1、項目目錄結構
2、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/maven-v4_0_0.xsd"><modelVersion>4.0.0</modelVersion><groupId>com.jege.spring.boot</groupId><artifactId>spring-boot-devtools</artifactId><packaging>war</packaging><version>1.0.0.RELEASE</version><name>spring-boot-mybatis</name><url>http://blog.csdn.net/je_ge</url><developers><developer><id>je_ge</id><name>je_ge</name><email>1272434821@qq.com</email><url>http://blog.csdn.net/je_ge</url><timezone>8</timezone></developer></developers><!-- 公共spring-boot配置,下面依賴jar文件不用在寫版本號 --><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>1.4.1.RELEASE</version><relativePath /></parent><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><java.version>1.8</java.version></properties><dependencies><!-- web --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><!-- 熱部署 --><!-- devtools可以實現頁面熱部署(即頁面修改后會立即生效,這個可以直接在application.properties文件中配置spring.thymeleaf.cache=false來實現) --><!-- 實現類文件熱部署(類文件修改后不會立即生效),實現對屬性文件的熱部署。 --><!-- 即devtools會監聽classpath下的文件變動,并且會立即重啟應用(發生在保存時機),注意:因為其采用的虛擬機機制,該項重啟是很快的 --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-devtools</artifactId><!-- optional=true,依賴不會傳遞,該項目依賴devtools;之后依賴boot項目的項目如果想要使用devtools,需要重新引入 --><optional>true</optional></dependency></dependencies><build><finalName>spring-boot-devtools</finalName><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><configuration><!-- 如果沒有該項配置,實際測試ok --><!-- <fork>true</fork> --></configuration></plugin><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><configuration><source>${java.version}</source><target>${java.version}</target></configuration></plugin></plugins></build> </project>3、application.properties的內容
#添加那個目錄的文件需要restart spring.devtools.restart.additional-paths=src/main/java #排除那個目錄的文件不需要restart spring.devtools.restart.exclude=static/**,public/**4、HelloController的內容
package com.jege.spring.boot.devtools;import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController;/*** @author JE哥* @email 1272434821@qq.com* @description:看看devtools模塊的快速*/ @RestController public class HelloController {@RequestMapping("/hello")public String hello() {// System.out.println("test");return "Hello World";} }5、Application的內容
package com.jege.spring.boot;import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;/*** @author JE哥* @email 1272434821@qq.com* @description:spring boot 啟動類*/@SpringBootApplication public class Application {public static void main(String[] args) {SpringApplication.run(Application.class, args);}}瀏覽器中輸入:
http://localhost:8080/hello
總結
以上是生活随笔為你收集整理的SpringBoot热部署之devtools案例(学习笔记)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: SpringBoot使用JdbcTemp
- 下一篇: 西安小吃街外面有米饭店吗?