项目更新JDK,由之前的1.7更新到1.8,启动tomcat时报错,提示:org.springframework.beans.factory.CannotLoadBeanClassException: Error loading class [com.zdcx.account.ajax.service.impl.OrderInvoiceServiceImpl] for bean with name 'userOrderInvoiceService' defined in file [C:\work\apache-tomcat-7.0.53\wtpwebapps\zdcx-account\WEB-INF\classes\com\zdcx\account\ajax\service\impl\OrderInvoiceServiceImpl.class]: problem with class file or dependent class; nested exception is java.lang.UnsupportedClassVersionError: com/zdcx/account/ajax/service/impl/OrderInvoiceServiceImpl :
Unsupported major.minor version 52.0 (unable to load class com.zdcx.account.ajax.service.impl.OrderInvoiceServiceImpl)
出现这个错误是因为编译的JDK版本,跟运行时所用的JDK版本不一致所导致的:低版本的jvm无法加载高版本的class文件造成的
现在梳理下项目中配置jdk的地方
1,设置Maven编译的版本,maven-compiler-plugin jdk版本 (在pom.xml文件中配置)
<plugins>
<!-- 指定编译版本 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<compilerArgument>-parameters</compilerArgument>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
2,项目的 java compiler
在项目名称上右键 -->选择Properties -->java compiler 选择jdk1.8
3,Eclipse全局Compiler
在eclipse中点击Window -->preferences --> java --> compiler
4,tomcat所用的jdk
在eclipse中点击Window -->preferences --> server--> Runtime Environment, 选中tomcat,点击Edit设置jdk
注:
出现这个错误是因为编译的JDK版本,跟运行时所用的JDK版本不一致所导致的:低版本的jvm无法加载高版本的class文件造成的
现在梳理下项目中配置jdk的地方
1,设置Maven编译的版本,maven-compiler-plugin jdk版本 (在pom.xml文件中配置)
<plugins>
<!-- 指定编译版本 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<compilerArgument>-parameters</compilerArgument>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
2,项目的 java compiler
在项目名称上右键 -->选择Properties -->java compiler 选择jdk1.8
3,Eclipse全局Compiler
在eclipse中点击Window -->preferences --> java --> compiler
4,tomcat所用的jdk
在eclipse中点击Window -->preferences --> server--> Runtime Environment, 选中tomcat,点击Edit设置jdk
注:
major.minor version 52.0 对应 jdk版本1.8
注:这篇最初我是写在163博客上的