Spring Boot - 不支持的major.minor版本51.0

时间:2015-03-25 17:43:07

标签: java spring maven

我已将Spring Boot应用程序部署到Tomcat 6服务器上,该服务器返回以下错误

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容器上本地app,没有问题。

我已按照此处的说明获取符合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>

这是项目方面

enter image description here

构建路径

enter image description here

我可以在我的本地服务器和部署打包的war文件之间忽略任何事情吗?我无法弄清楚为什么我的项目会持有任何1.7依赖项。

1 个答案:

答案 0 :(得分:3)

请参阅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依赖项添加排除项可能会为您解决此问题。