Java 如何在 IDEA Intellij 上使用 Spring-boot 进行自动重新加载

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33349456/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 14:35:44  来源:igfitidea点击:

how to make auto reload with Spring-boot on IDEA Intellij

javaspringspring-bootintellij-ideajunit

提问by u1559249

I had wrote a project base on Spring-boot,tomcat,freemarker, I run it successful, but whenever I modify some templates and java class, I must restart server or use "reload changed classes" menu on Intellij to make the changes become effective. It wastes lots time!

我写了一个基于 Spring-boot,tomcat,freemarker 的项目,运行成功,但是每当我修改一些模板和 java 类时,我必须重新启动服务器或使用 Intellij 上的“重新加载更改的类”菜单使更改生效. 浪费很多时间!

Then I try to use springloaded as the official said:

然后我尝试使用 springloaded 作为官方所说的

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <dependencies>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>springloaded</artifactId>
            <version>1.2.0.RELEASE</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/lib/springloaded-1.2.0.RELEASE.jar</systemPath>
        </dependency>
    </dependencies>
</plugin>

then I rerun server, but doesn't work as expected! I still need to restart server after any change on template or class.

然后我重新运行服务器,但没有按预期工作!在对模板或类进行任何更改后,我仍然需要重新启动服务器。

How could I configure the springloaded to auto reload. Thanks a lot!

我如何配置弹簧加载以自动重新加载。非常感谢!



The version of Spring-boot is 1.3.0RC1

Spring-boot 的版本是 1.3.0RC1

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.3.0.RC1</version>
</parent>

maven version:3.2 jdk:1.8 intellij :14.1.5 os:windows 8.1 64 bit

Maven 版本:3.2 jdk:1.8 智能:14.1.5 操作系统:windows 8.1 64 位

回答by wang.chun

CTRL+F9to make project with debugging. The idea is to make the project automatically work while not running or debugging!

CTRL+F9使项目与调试。这个想法是让项目在不运行或调试时自动工作!

Setting->Build->Compiler->check Make project automatically.

设置->构建->编译器->勾选自动生成项目。

回答by Hocine Ben

First, be sure that you added spring-boot-devtoolsas dependency:

首先,确保您添加spring-boot-devtools为依赖项:

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

Second, verify that the option check-box File->Setting –> Build, Execution, Deployment –> Compiler–>Build project automaticallyis selected.

其次,验证选项复选框File->Setting –> Build, Execution, Deployment –> Compiler–>自动生成项目被选中。

Last, press SHIFT+CTRL+Afor Linux/Windows users or Command+SHIFT+Afor Mac users, then type registryin the opened pop-up window. Scroll down to Registry...using the down arrow key and hit ENTERon Registry.... In the Registrywindow verify the option compiler.automake.allow.when.app.runningis checked.

最后,SHIFT+CTRL+A对于 Linux/Windows 用户或Command+SHIFT+AMac 用户,按,然后在打开的弹出窗口中键入registry。向下滚动到Registry...使用向下箭头键和命中ENTERRegistry...。在Registry窗口中验证选项compiler.automake.allow.when.app.running被选中。

The instructions above are taken from here

以上说明取自here

回答by bitfishxyz

For macOS

对于 macOS

  1. Preference -> Compiler -> check BUild project on build automatically asds

  2. shift + command + A enter image description here

  1. 首选项 -> 编译器 -> 在构建时自动检查 BUild 项目 asds

  2. shift + 命令 + A 在此处输入图片说明

enter image description here

在此处输入图片说明

check compiler.automake.allow.when.app.running

查看 compiler.automake.allow.when.app.running