Spring启动应用程序,基于eclipse,不支持的major.minor版本52.0

时间:2017-03-22 06:16:22

标签: java eclipse maven

详细信息

Exception in thread "main" java.lang.UnsupportedClassVersionError: com/mysql/cj/jdbc/Driver : Unsupported major.minor version 52.0
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:278)

系统:

Windows 64

平台:

Eclipse Neon.1

Maven 3

爪哇

java 1.8和java 1.7都安装了

JAVA_HOME指向1.8 jdk PATH =%PATH%;%JAVA_HOME%/ bin /

Eclipse执行Java应用程序

path\to\Java\jdk1.7.0_80\bin\javaw.exe

Eclipse项目构建路径

JRE System Library [JavaSE-1.7]

Maven Dependencies

的pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.4.2.RELEASE</version>
  </parent>

  <groupId>com.worldline.cn.workbench</groupId>
  <artifactId>orm-base</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <name>orm-base</name>
  <description>orm-base</description>

    <properties>
        <java.version>1.7</java.version>
    </properties>

  <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis-spring</artifactId>
            <version>1.3.1</version>
        </dependency>
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis</artifactId>
            <version>3.4.1</version>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>6.0.5</version><!--$NO-MVN-MAN-VER$-->
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <version>1.5.2.RELEASE</version>
            <scope>test</scope>
        </dependency>

    </dependencies> 


    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

需要什么?

我知道这通常是因为:

项目由java 1.8编译,但由java 1.7(或更低版本)执行。

但我检查了我的Eclipse,

Java编译器:

checked *use compliance from execution environment 'Java SE-1.7' on the 'Java Build Path'*

checked *enable project specific settings*

运行配置:

JRE tab:

    Runtime JRE:

        checked: *Project execution environment 'JavaSE-1.7'(jdk1.7.0_80)*

所以你看,我用1.7编译了项目并用1.7 ...

运行它

2 个答案:

答案 0 :(得分:2)

为JDK1.8编译mysql jar的版本

请参阅此link以获取正确的版本

e.g。

Connector/J version JRE Supported
5.1                 1.5.x, 1.6.x, 1.7.x*, 1.8.x**

答案 1 :(得分:-1)

您的编译器指向JDK 1.8,运行时是JDK 1.7 ...您可以更改项目的java编译器配置。 1.在Eclipse中 - &gt;右键单击项目 - &gt; Java编译器 - &gt;使用与执行环境相同的编译器版本。