springboot热更新

在代码开发过程中 经常需要在不重启项目的情况下 动态更新代码或者配置文件

下面我们来看看 具体应该怎么操作

pom.xml

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtool</artifactId>
</dependency>

 

配置文件 application.properties

server.port:8080
url:http://localhost

  

WebController

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class WebController {
    @Autowired
    private Environment env;

    @RequestMapping("/getUrl")
    public String test(){
        return env.getProperty("url");
    }

}

 

以这种方式同样可以更新代码

原文地址:https://www.cnblogs.com/lnas01/p/10351436.html