springboot + jdk6:Unsupported major.minor version 51.0

官方文档:
How to use Java 6

If you want to use Spring Boot with Java 6 there are a small number of configuration changes that you will have to make. The exact changes depend on your application’s functionality.

Embedded servlet container compatibility

If you are using one of Boot’s embedded Servlet containers you will have to use a Java 6-compatible container. Both Tomcat 7 and Jetty 8 are Java 6 compatible. See Use Tomcat 7 and Use Jetty 8 for details.

JTA API compatibility

While the Java Transaction API itself doesn’t require Java 7 the official API jar contains classes that have been built to require Java 7. If you are using JTA then you will need to replace the official JTA 1.2 API jar with one that has been built to work on Java 6. To do so, exclude any transitive dependencies on javax.transaction:javax.transaction-api and replace them with a dependency on org.jboss.spec.javax.transaction:jboss-transaction-api_1.2_spec:1.0.0.Final

1、错误:java.lang.UnsupportedClassVersionError: javax/annotation/ManagedBean : Unsupported major.minor version 51.0

解决:
若你的项目直接或间接继承spring-boot-dependencies(比如spring-boot-starter-parent)进行构建,那你只需进行第三步即可!

若你使用<scope>import</scope>,将spring-boot-dependencies添加到自己的dependencyManagement片段–如下:

 <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>${spring-boot.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

则可以:
1、进入 spring-boot-dependencies-1.3.6.RELEASE.pom文件
2、搜索“tomcat.version”,将所有该版本依赖项拷贝到你的项目pom文件中。
3、添加 <properties> 项: <tomcat.version>7.0.52</tomcat.version>
<!--因为:Tomcat 7 支持jdk6-->

2、错误:java.lang.UnsupportedClassVersionError: javax/transaction/SystemException : Unsupported major.minor version 51.0

解决:

<dependency>
     <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-data-jpa</artifactId>
      <exclusions>
          <exclusion>
              <groupId>javax.transaction</groupId>
              <artifactId>javax.transaction-api</artifactId>
          </exclusion>
      </exclusions>
</dependency>
<!--official Transaction API jar require Java 7 so replace javax.transaction-api with the jboss-transaction-api -->
<dependency>
    <groupId>org.jboss.spec.javax.transaction</groupId>
    <artifactId>jboss-transaction-api_1.2_spec</artifactId>
    <version>1.0.0.Final</version>
</dependency>

你可能感兴趣的:(springboot)