我写了这个简单的代码
package com.abhi;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
@EnableAutoConfiguration
public class HelloWorldController {
@RequestMapping("/")
@ResponseBody
String getMessage() {
return "<h1>Hello World</h1>";
}
public static void main(String args[]) {
SpringApplication.run(HelloWorldController.class, args);
}
}
我正在使用 Gradle(Inside IntelliJ Idea)编译和运行它。
group 'com.abhi'
version '1.0-SNAPSHOT'
apply plugin: 'java'
apply plugin: 'application'
mainClassName = "com.abhi.HelloWorldController"
repositories {
mavenCentral()
}
dependencies {
compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '1.3.0.RELEASE'
}
现在,当我在 intellij 中运行它并在 http://localhost:8080 访问它时.它工作正常。但是如果我将字符串更改为 Hello World New 并重新编译...浏览器在刷新时仍然显示旧的“Hello World”。
那么有没有一种方法可以让我更改字符串并重新编译,并且我的更改会立即生效,而无需重新启动 Web 服务器?
最佳答案
从 Spring Boot 1.3.0 开始,Developer tools offer a live reload feature (还有更多!)。
关于java - 在 Spring Boot 中自动重新加载新类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33860145/