源发行版本 17 需要目标发行版 17

1.版本不匹配问题,让Java Compiler里面的版本一致

2.再次运行时,还是报错:springframework/boot/SpringApplication has been compiled by a more recent version of the Java Runtime .(class file version 61.0), this version of the Java Runtime only recognizes (class file versions up to 55.0)

springframework/boot/SpringApplication 
has been compiled by a more recent version of the Java Runtime .
(class file version 61.0), 
this version of the Java Runtime only recognizes 
(class file versions up to 55.0)

解决办法:点击File—>点击Project Structure—>点击Module—>Language level改为11

3.又运行,报错:/C:/Users/.m2/repository/org/springframework/boot/spring-boot/3.0.4/spring-boot-3.0.4.jar!/org/springframework/boot/SpringApplication.class类文件具有错误的版本 61.0, 应为 55.0,请删除该文件或确保该文件位于正确的类路径子目录中。

原因是SpringBoot使用了3.0或者3.0以上,Spring官方发布从Spring6以及SprinBoot3.0开始最低支持JDK17,需要将SpringBoot版本降低为3.0以下。

3.0.4更改为2.7.5 17改为11 刷新Maven,重新启动即可

4.再次运行是,又报错:Web application could not be started as there was no org.springframework.boot.web.servlet.server.ServletWebServerFactory bean defined in the context

public class APP {
          
   
    public static void main(String[] args) {
          
   
        SpringApplication.run(APP.class);
    }
}

缺失了@SpringBootApplication 终于解决了!

经验分享 程序员 微信小程序 职场和发展