简体   繁体   中英

Springboot Devtools not hot reloading?

I haven't used spring in a while, and I'm trying to get spring boot dev tools to perform hot reloading. I've imported the web and spring boot dependencies from start.spring.io project generator and made a uri for "/hello". I can run the project but changing the uri values doesn't hot reload and I don't believe that the hot reloading is working. From what I've found on searching the internet, the only necessary step is to add the hot reloading dependency in your pom file:

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

My entire pom.xml file is as follows (generated from the start.spring.io website):

<?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>

And my web uri file is as follows (works, but without hot reloading):

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);
        }

}

This is as simple an application as I think it is possible to build, so I'm confused on what extra necessary step is needed to make hot reloading work. It does not appear to be documented say here ( https://www.baeldung.com/spring-boot-devtools ) other than to add the dependency. If it matters I'm running ubuntu 20.04.

EDIT:

I am running the application in the terminal on port :8080 and using vim to modify the uri file while the application is running. Since java has a lot of plugins for various IDEs someone suggested that it is worth mentioning that.

如果您不使用 IDE,您可以使用./mvnw compile并且项目将在编辑器运行时重新编译。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM