我已经有一段时间没有使用spring了,我正在尝试使用spring boot dev工具来执行热重新加载。我已经从start.spring.io项目生成器中导入了web和spring引导依赖项,并为"/hello“创建了一个uri。我可以运行该项目,但是更改uri值不会进行热重新加载,并且我不相信热重新加载是有效的。根据我在互联网上搜索到的结果,唯一需要做的就是在你的pom文件中添加热重载依赖:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>我的整个pom.xml文件如下所示(从start.spring.io网站生成):
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.java</groupId>
<artifactId>java_app</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>java_app</name>
<description>Web Project</description>
<properties>
<java.version>11</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-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</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>我的web uri文件如下所示(工作,但不需要热重载):
package com.java.java_app;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@SpringBootApplication
@RestController
public class JavaAppApplication {
public static void main(String[] args) {
SpringApplication.run(JavaAppApplication.class, args);
}
@GetMapping("/hello")
public String hello(@RequestParam(value = "name", defaultValue = "World") String name){
return String.format("Hello %s!", name);
}
}这是一个我认为可以构建的简单的应用程序,所以我不知道需要什么额外的必要步骤才能使热重新加载工作。除了添加依赖项之外,它似乎没有记录在这里(https://www.baeldung.com/spring-boot-devtools)。如果重要的话,我正在运行ubuntu 20.04。
编辑:
我在终端的端口8080上运行应用程序,并在应用程序运行时使用vim修改uri文件。由于java有许多用于各种IDE的插件,有人建议值得一提的是。
发布于 2020-11-19 06:57:06
如果您没有使用集成开发环境,则可以使用./mvnw compile,并且在编辑器运行时项目将重新编译。
https://stackoverflow.com/questions/64902534
复制相似问题