关于这个问题网上有好多种解决方法:
第一种:注掉 <scope>provided</scope>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<!--<scope>provided</scope>-->
</dependency>
第三种:如果pom.xml中没有下面的依赖,需要添加上下面的依赖,如果是<artifactId>spring-boot-starter</artifactId>,则需要改成<artifactId>spring-boot-starter-web</artifactId>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
第二种:将热部署的代码做如下修改
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</plugin>
</plugins>
</build>
我在遇到这个问题之后,先按照第一种情况改了,然后还是报错,没生效,然后又按照第二种方式添加上面的代码,结果好使了。个人觉得是在第一次改完之后,没有部署,所以导致修改没有生效。