Spring Boot如何在不重新启动服务器的情况下加载代码

shu*_*ham 10 spring spring-boot

这是一个面试问题,我可能会对您的代码进行一些更改,它是一个Spring启动应用程序,如果不重新启动服务器,您就可以获得这些更改.如果是,那么在春季启动时怎么可能呢?

我想知道在Spring Boot中怎么可能.

fg7*_*8nc 7

在您的项目中添加spring-boot-devtools模块,其中包括LiveReload服务器,该服务器可用于在资源发生更改时触发浏览器刷新。您可以从livereload.com下载浏览器扩展。

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
    </dependency>
</dependencies>
Run Code Online (Sandbox Code Playgroud)


小智 6

您只需要devtoolpom.xmlyml 文件属性中添加依赖项:

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

# for not restarting the server every time
spring.devtools.restart.enabled:  false
Run Code Online (Sandbox Code Playgroud)