首先说下原因,根据官网所说,以后jdk版本主流为17,而且在2023年11月24日,3.0以下的版本不再支持了,升级为17后大部分用户需要修改import相关API的时候,要用jakarta替换javax。比如:原来引入的地方,需要替换为
再说解决办法,网上查到的解决办法有两种
第一种是创建SpringBoot时,把/或者/替换为 /
第二种办法就是升级到17
最后我试了下创建SpringBoot项目时就使用17创建,创建完后进入pom文件,修改版本号,我的pom文件如下
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="/POM/4.0.0" xmlns:xsi="http:///2001/XMLSchema-instance"
xsi:schemaLocation="/POM/4.0.0 /xsd/maven-4.0.">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId></groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.17</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId></groupId>
<artifactId>testvesion</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>testvesion</name>
<description>Demo project for Spring Boot</description>
<properties>
<>1.8</>
</properties>
<dependencies>
<dependency>
<groupId></groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId></groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId></groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId></groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId></groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>
之后就可以运行了