IDEA配置动态编译,立刻看到修改效果

1. 背景
  • 项目使用Spring Boot架构,自己想为http://localhost:8080/创建一个默认的访问页面。
  • 访问页面很简单,直接打印遗传字符记号,总比空白页还报错好看。
    在这里插入图片描述
  • 在Aplication里面很快写好了相关的代码
@RestController
@SpringBootApplication
public class DruidPlatformApplication extends SpringBootServletInitializer {
    // ....
    @RequestMapping
    public String hello(){
        return "Hello Spring Boot!这是你的第一个页面。";
    }
}
  • 运行以后的效果如下:
    在这里插入图片描述
  • 自己觉得中英结合太丢分了,想删除中文部分。这时需要重新运行项目。
2. 动态编译配置
  1. 首先,在pom.xml中添加热部署依赖。
<!--添加热部署-->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-devtools</artifactId>
    <optional>true</optional>
</dependency>
  1. 接着,进行热部署配置。(上述博客的配置有问题,解决办法参考:spring-boot-maven-plugin not found的解决方案
<!--热部署配置-->
<plugin>
     <groupId>org.springframework.boot</groupId>
     <artifactId>spring-boot-maven-plugin</artifactId>
     <!--一定要指定版本,不然会报错  Could not find artifact  ... -->
     <version>2.2.2.RELEASE</version>
     <configuration>
         <!--fork:如果没有该项配置,整个devtools不会起作用-->
         <fork>true</fork>
     </configuration>
 </plugin>
  1. 设置idea的自动编译:File —> Settings —> Compiler,勾选红框中的选项
    在这里插入图片描述
  • 修改代码以后,通过Ctrl + F9就可以实现自动编译,能立马看到修改效果!
    在这里插入图片描述
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值