gpt4 book ai didi

java - 在 Spring Boot 中自动重新加载新类

转载 作者:行者123 更新时间:2023-11-29 07:37:34 27 4
gpt4 key购买 nike

我写了这个简单的代码

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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com