2

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

enter image description here

Build path

enter image description here

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.

Clay Banks
  • 4,483
  • 15
  • 71
  • 143
  • 3
    It means that one of your dependencies was compiled for Java 7. If you want the application to run in Java 6, you will need to remove that dependency. Search through them to see what is referencing `javax.transaction.SystemException`. – Steve Mar 25 '15 at 17:49
  • Good point @Steve - the `javax-servlet` dependency I believe is referencing 3.1 that could be an issue - I'll check it out. However it's strange that the app runs on my local server without issue – Clay Banks Mar 25 '15 at 17:51
  • 1
    btw - I would guess that if it works locally, it may be worth looking at your `provided` dependencies, as they will be different in each environment. – Steve Mar 25 '15 at 17:52
  • I'll look into the version that the remote server is using – Clay Banks Mar 25 '15 at 17:56
  • Maybe double check if your local container is really running with Java 6. I shot myself in the foot multiple times when I messed up my *JAVA_HOME*... – cringe Mar 25 '15 at 18:13

1 Answers1

3

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.

David Conneely
  • 896
  • 6
  • 9
  • Thanks @DavidC this was the exact issue. Hopefully we can get our runtime/servers upgraded in the very near future – Clay Banks Mar 25 '15 at 19:15