简体   繁体   中英

Spring Boot - Unsupported major.minor version 51.0

I've got a Spring Boot application deployed onto a Tomcat 6 Server which is returning the following error

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)

I know this translates to "you can't run apps compiled with JRE 1.7 on this container", however my project is indeed compiled with the JRE 1.6 runtime and I've tested the app locally on my own Tomcat 6 container with no issue.

I've followed the directions here to get my application Servlet-2.5 compliant: http://docs.spring.io/spring-boot/docs/current/reference/html/howto-traditional-deployment.html

Here's my PersistenceConfig.xml LocalEntityManager config which is returned with the error:

@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;
   }

And my pom.xml dependencies

<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>

Here's the project facets

在此处输入图片说明

Build path

在此处输入图片说明

Might there be anything I'm overlooking between my local server and deploying the packaged war file? I can't figure out why my project is holding onto any 1.7 dependencies.

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

The .war file you are deploying may contain both of javax.transaction-api-1.2.jar (contains Java 7 compiled class files) and jboss-transaction-api_1.2_spec-1.0.0.FINAL.jar (contains Java 6 compiled class files) because of the referenced issue #2347. Which of these two .jar files gets loaded first could be environment-specific, which might explain why you got different results locally?

If that's what's happening, then adding an exclusion for the non-JBoss dependency will probably resolve it for you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM