【问题标题】:Spring Boot - Unsupported major.minor version 51.0Spring Boot - 不支持的 major.minor 版本 51.0
【发布时间】:2015-05-29 13:03:47
【问题描述】:

我在 Tomcat 6 服务器上部署了一个 Spring Boot 应用程序,它返回以下错误

org.springframework.beans.factory.BeanCreationException: Error creating bean
with name 'entityManagerFactory' defined in class path resource [com/myApp/PersistenceJPAConfig.class]: 
Invocation of init method failed; nested exception is 
java.lang.UnsupportedClassVersionError: 
javax/transaction/SystemException : 
Unsupported major.minor version 51.0 (unable to load class javax.transaction.SystemException)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1566)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)

我知道这意味着“你不能在这个容器上运行用 JRE 1.7 编译的应用程序”,但是我的项目确实是用 JRE 1.6 运行时编译的,我已经在我自己的 Tomcat 6 容器上本地测试了应用程序没问题。

我已按照此处的说明使我的应用程序符合 Servlet-2.5:http://docs.spring.io/spring-boot/docs/current/reference/html/howto-traditional-deployment.html

这是我的 PersistenceConfig.xml LocalEntityManager 配置,它返回错误:

@Configuration
@EnableTransactionManagement
@EnableJpaRepositories("com.myapp.repositories")
@PropertySource("classpath:application.properties")
public class PersistenceJPAConfig{

    @Autowired
    private Environment environment;

    @Bean
    public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
        LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
        em.setDataSource(dataSource());
        em.setPackagesToScan(new String[] { "com.myapp" });
        JpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
        em.setJpaVendorAdapter(vendorAdapter);
        em.setJpaProperties(additionalProperties());
        return em;
   }

还有我的 pom.xml 依赖项

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

<dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
        </dependency>
        <dependency>
            <groupId>commons-fileupload</groupId>
            <artifactId>commons-fileupload</artifactId>
            <version>1.3.1</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-batch</artifactId>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>jstl</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>
        <dependency>
            <groupId>net.sourceforge.jtds</groupId>
            <artifactId>jtds</artifactId>
            <version>1.2.4</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.jaxrs</groupId>
            <artifactId>jackson-jaxrs-json-provider</artifactId>
            <version>2.5.1</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
        </dependency>
        <dependency>
            <groupId>org.dbunit</groupId>
            <artifactId>dbunit</artifactId>
            <version>2.5.0</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-legacy</artifactId>
            <version>1.0.1.RELEASE</version>
        </dependency> 
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>

        </dependency>

    </dependencies>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    </properties>

    <build>
        <plugins>
            <!-- <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> 
                <configuration> <failOnMissingWebXml>false</failOnMissingWebXml> </configuration> 
                <executions> <execution> <goals> <goal>repackage</goal> </goals> </execution> 
                </executions> </plugin> -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>

                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

这是项目方面

构建路径

在我的本地服务器和部署打包的 war 文件之间可能有什么我忽略的东西吗?我不明白为什么我的项目会保留任何 1.7 依赖项。

【问题讨论】:

  • 这意味着您的依赖项之一是为 Java 7 编译的。如果您希望应用程序在 Java 6 中运行,则需要删除该依赖项。搜索它们以查看引用 javax.transaction.SystemException 的内容。
  • 好点@Steve - 我相信javax-servlet 依赖项引用了可能是一个问题的3.1 - 我会检查一下。但是奇怪的是,该应用程序在我的本地服务器上运行没有问题
  • btw - 我猜如果它在本地工作,可能值得查看您的 provided 依赖项,因为它们在每个环境中都会有所不同。
  • 我会查看远程服务器正在使用的版本
  • 也许仔细检查你的本地容器是否真的在运行 Java 6。当我搞砸我的 JAVA_HOME...

标签: java spring maven


【解决方案1】:

参见Spring Boot GitHub issue #2347 that javax.transaction:javax.transaction-api-1.2 not compatible with Java 6Spring Boot documentation about use on Java 6

您正在部署的 .war 文件可能同时包含 javax.transaction-api-1.2.jar(包含 Java 7 编译的类文件)和 jboss-transaction-api_1.2_spec-1.0.0.FINAL.jar(包含 Java 6 个已编译的类文件),因为引用的问题 #2347。这两个 .jar 文件中的哪一个首先加载可能是特定于环境的,这可以解释为什么您在本地得到不同的结果?

如果发生了这种情况,那么为非 JBoss 依赖项添加排除项可能会为您解决问题。

【讨论】:

  • 感谢@DavidC,这正是问题所在。希望我们可以在不久的将来升级我们的运行时/服务器
猜你喜欢
  • 1970-01-01
  • 2014-03-17
  • 1970-01-01
  • 1970-01-01
  • 2016-01-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-07-25
相关资源
最近更新 更多