springboot + jdk6:Unsupported major.minor version 51.0

本文介绍了如何在使用SpringBoot时解决与Java 6不兼容的问题,包括针对嵌入式Servlet容器(如Tomcat 7和Jetty 8)的配置调整,以及解决JTA API中因类版本不支持引发的错误。具体解决方法涉及排除并替换官方JTA 1.2 API jar,以及针对特定错误`java.lang.UnsupportedClassVersionError`的处理策略。
摘要由CSDN通过智能技术生成

官方文档:
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>
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值