学习springmvc中,报出异常:

异常有用信息如下:

java.lang.IllegalStateException: 启动子级时出错
        at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:729)
        at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:698)
      ……

Caused by: org.apache.catalina.LifecycleException: 无法启动组件[StandardEngine[Catalina].StandardHost[localhost].StandardContext[/springmvc]]
        at org.apache.catalina.util.LifecycleBase.handleSubClassException(LifecycleBase.java:440)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:198)

……

Caused by: java.lang.UnsupportedClassVersionError: org/springframework/web/SpringServletContainerInitializer 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 52.0 (无法载入的类 [org.springframework.web.SpringServletContainerInitializer])
        at org.apache.catalina.loader.WebappClassLoaderBase.findClassInternal(WebappClassLoaderBase.java:2521)
 

可以看到报错信息是:代码编译是由java 61.0版本(对应jdk 17)进行编译

运行时却运行java 52.0版本上,

下面介绍一下跟jdk有关的配置,因为这是springmvc项目,所以idea中有三个地方可以设置jdk:

1.[setting]-[compiler] 中的设置

其中

project bytecode version是设置jdk 运行版本

per-moudle bytecode version 是设置jdk 编译时版本(ide其他版本可能叫Project compiler output)

 2.[project structure]-[modules]中的设置

其中

moudule sdk 是设置jdk编译版本

3. [edit configurations…] JRE版本

这里设置的是tomcat运行时版本

springmvc运行tomcat版本的服务上,所以要吧3改jre改成17

注意:

1.[project structure]中配置是高于[setting]的

2.在当前场景下改setting中的jdk运行时版本没有用,是因为此项目是跑在tomcat 中,若是springboot项目那可能会有用

原文地址:https://blog.csdn.net/whenstudyswim/article/details/128440930

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。

如若转载,请注明出处:http://www.7code.cn/show_9443.html

如若内容造成侵权/违法违规/事实不符,请联系代码007邮箱:suwngjj01@126.com进行投诉反馈,一经查实,立即删除

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注