在学习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项目那可能会有用