spring-boot-devtools

Create a new Maven Project  and  we have two class under the package com.example.demo like below screen shot.

This page mainly focus on how to make the change you make ready to show the result without restarting  spring boot application with Maven.

package com.example.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class DemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }
}
package com.example.demo;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloController {
    @RequestMapping(value = "hi" , method = RequestMethod.GET)
    public String sayHi() {
        return "Hello World!";
    }

}
<?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.example</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>demo</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.6.RELEASE</version>
        <relativePath/>
    </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-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>
            </plugin>
        </plugins>
    </build>

</project>

Then,run the DemoApplication as Java Application or Spring Boot App (if you are using STS),after the application starts up,input the link localhost:8080/hi ,you will get the Hello World! as the output.

But when you want to change the RequestMapping from "hi" to "hello" ,to make it ready to use you need to change it and restart the application.

with spring-boot-devtools we just change the code and save it without restart the application manually,spring boot help us restart the application .

To achieve this , all you need to do are adding  the spring-boot-devtools dependency in the pom.xml and make sure Project>build automatically is chosen in the IDE

<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <optional>true</optional>
    </dependency>

On the condition that you add the dependency in the pom.xml file and you don‘t choose the build automatically within the IDE(Eclipse or STS here),then when you change the the RequestMapping from "hi" to "hello" and save it,spring boot will not restart the application for you ,you have to bulid the pom file and restart the application manualy.Because the spring-boot-devtools monitor the code under the target to restart the application to make the change you made ready to use ,so you choose the build atuomatically and change RequestMapping and save it ,the IDE build and the code under the target is  updated to trigger the restart of the spring boot application automatically.

For more details,please refer the spring boot  devtools reference guide : http://docs.spring.io/spring-boot/docs/current/reference/html/using-boot-devtools.html

				
时间: 2024-10-10 07:31:51

spring-boot-devtools的相关文章

使用IDEA 中 实现springboot 热部署 (spring boot devtools版)

第一步:添加springboot的配置文件 首先我先贴出我的配置 添加依赖包 <!-- spring boot devtools 依赖包. --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <optional>true</optional> <

IDEA新建SpringBoot+MySQL+MyBatis+Lombok+Spring Boot DevTools项目

一,IDEA新建SpringBoot+MySQL+MyBatis+Lombok+Spring Boot DevTools项目 1,新建项目的选中项 2,新建后我们需要配置勾选这个自动编译 3,按住shift+alt+ctrl+/,然后选中registry 4,然后选中这个选项 5,然后在 pom.xml文件添加以下代码,开启热部署工具,不配置不生效 <build> <plugins> <plugin> <groupId>org.springframework

使用spring boot devtools不要多此一举加try...catch

spring-boot-devtools是个好东西,在开发调试时可以随时热部署,不用每次手工启停.前两天一个项目查log,发现总有这样的错误日志输出: org.springframework.boot.devtools.restart.SilentExitExceptionHandler$SilentExitException at org.springframework.boot.devtools.restart.SilentExitExceptionHandler.exitCurrentTh

Spring Boot 属性配置和使用

spring Boot 允许通过外部配置让你在不同的环境使用同一应用程序的代码,简单说就是可以通过配置文件来注入属性或者修改默认的配置. Spring Boot 系列 Spring Boot 入门 Spring Boot 属性配置和使用 Spring Boot 集成MyBatis Spring Boot 静态资源处理 Spring Boot - 配置排序依赖技巧 Spring Boot - DevTools 介绍 Spring Boot 支持多种外部配置方式 这些方式优先级如下: 命令行参数 来

Spring Boot 集成MyBatis

Spring Boot 集成MyBatis 在集成MyBatis前,我们先配置一个druid数据源. Spring Boot 系列 Spring Boot 入门 Spring Boot 属性配置和使用 Spring Boot 集成MyBatis Spring Boot 静态资源处理 Spring Boot - 配置排序依赖技巧 Spring Boot - DevTools 介绍 Spring Boot 集成druid druid有非常多个配置选项,使用Spring Boot 的配置文件能够方便的

spring boot热部署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"> <modelVersi

Spring Boot Questions- Part 2

What is spring-boot-devtools ? Applications that use spring-boot-devtools will automatically restart whenever files on the classpath change. This can be a useful feature when working in an IDE as it gives a very fast feedback loop for code changes. /

Spring Boot中使用FastJson解析Json数据

首先我们创建一个maven工程,如下图: 第二步:配置pom.xml <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.4.1.RELEASE</version> </parent> <properties> <p

spring boot: spring-data-jpa (Repository/CrudRepository) 数据库操作, @Entity实体类持久化

SpringBoot实现的JPA封装了JPA的特性, Repository是封装了jpa的特性(我是这么理解的) 1在pom.xml引入mysql, spring-data-jpa依赖 2.在src/main/resource/下新建applicatoin.properties配置文件,并配置数据库连接 3.在application.properties配置jpa配置信息 4.编写实例 热部署pom.xml配置 <!-- spring boot devtools 热部署 --> <dep

spring boot:创建一个简单的web(maven web project)

1.新建一个maven web project; 2.在pom.xml文件中添加相应的依赖包: 3.新建一个HelloController请求控制类: 4.编写index.jsp页面: 5.编写启动类App.java 6.启动应用程序进行代码测试 pom.xml配置 <!-- Inherit defaults from Spring Boot --> <parent> <groupId>org.springframework.boot</groupId> &