springboot系列二 devtools熱部署 (2.1.0.RELEASE版本)

spring-boot-devtools 能夠動態編譯java類。好比在開發過程當中,修改了某個java類,可是重啓須要好長時間,這個時候用devtools能很快編譯好修改的java代碼,實現熱部署java

使用:web

pom依賴:spring

<parent>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-parent</artifactId>
	<version>2.1.0.RELEASE</version>
</parent>

<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>
		<optional>true</optional>
	</dependency>
</dependencies>

<build>
	<plugins>
		<plugin>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-maven-plugin</artifactId>
		</plugin>
	</plugins>
</build>

啓動類和接口:app

@RestController
@EnableAutoConfiguration
public class HelloWorldApp {

    @RequestMapping("/")
    String home() {
        return "Hello World";
    }

    public static void main(String[] args) throws Exception {
        SpringApplication.run(HelloWorldApp.class, args);
    }
}

啓動後訪問 localhost:8080maven

Hello World

修改 home() 方法:ide

@RequestMapping("/")
String home() {
	return "Hello World update";
}

在開發ide的菜單,點擊Build->Recompile從新編譯,編譯成功後,訪問localhost:8080spring-boot

Hello World update
相關文章
相關標籤/搜索