1. 背景
- 项目使用Spring Boot架构,自己想为
http://localhost:8080/
创建一个默认的访问页面。
- 访问页面很简单,直接打印遗传字符记号,总比空白页还报错好看。

- 在Aplication里面很快写好了相关的代码
@RestController
@SpringBootApplication
public class DruidPlatformApplication extends SpringBootServletInitializer {
@RequestMapping
public String hello(){
return "Hello Spring Boot!这是你的第一个页面。";
}
}
- 运行以后的效果如下:

- 自己觉得中英结合太丢分了,想删除中文部分。这时需要重新运行项目。
2. 动态编译配置
- 这时,自己想起了以前学习Spring Boot时,使用的动态编译。
- 具体参考了博客:IDEA 编写 SpringBoot 项目自动编译刷新 与 同一应用启动多次
- 首先,在
pom.xml
中添加热部署依赖。
<dependency>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-devtoolsartifactId>
<optional>trueoptional>
dependency>
- 接着,进行热部署配置。(上述博客的配置有问题,解决办法参考:spring-boot-maven-plugin not found的解决方案)
<plugin>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-maven-pluginartifactId>
<version>2.2.2.RELEASEversion>
<configuration>
<fork>truefork>
configuration>
plugin>
- 设置idea的自动编译:File —> Settings —> Compiler,勾选红框中的选项

- 修改代码以后,通过
Ctrl + F9
就可以实现自动编译,能立马看到修改效果!
