I have two servers with the following characteristics:
- Oracle Linux Server Release 7
- Java jre1.8.0_221
- apache-tomcat-8.5.54
Both servers have the same environment variables and tomcat configurations declared.
I have a Maven project with which I generate a .war that I deploy in the tomcat. I have all the libraries and dependencies defined in the pom.xml of the project.
Specifically, the one I would need that fails:
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>1.0.2</version>
</dependency>
The DB connection is defined in the context.xml in the same way in both tomcats, and the applicationContext.xml has this code defined about the part that fails.
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="packagesToScan" value="com.XXXX.XXXXX.model" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
</property>
<property name="jpaProperties">
<props>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
<prop key="hibernate.show_sql">false</prop>
<prop key="hibernate.format_sql">false</prop>
</props>
</property>
</bean>
On one of the servers the application correctly displays, and on the other it gives me the following error that I see in the tomcat logs:
14-May-2020 16:20:10.315 INFO [localhost-startStop-9] org.apache.catalina.core.ApplicationContext.log No Spring WebApplicationInitializer types detected on classpath 14-May-2020 16:20:10.457 INFO [localhost- startStop-9] org.apache.catalina.core.ApplicationContext.log Initializing Spring root WebApplicationContext 14-May-2020 16:20:10.992 SEVERE [localhost-startStop-9] org.apache.catalina.core.StandardContext.listenerStart Exception sending context initialized event to listener instance of class [org.springframework.web.context.ContextLoaderListener] org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: javax.persistence.spi. PersistenceUnitInfo.getSharedCacheMode()Ljavax/persistence/SharedCacheMode; at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1578) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545) at org.springframework.beans.factory .support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton( DefaultSingletonBeanRegistry.java:230) at org.springframework.beans.factory. run(HostConfig.java:1841) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent .ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748) Caused by: java. lang.NoSuchMethodError: javax.persistence.spi.PersistenceUnitInfo.getSharedCacheMode()Ljavax/persistence/SharedCacheMode; at org.hibernate.jpa.boot.internal.PersistenceUnitInfoDescriptor.getSharedCacheMode(PersistenceUnitInfoDescriptor.java:104) at org.hibernate.jpa.internal.util.LogHelper.logPersistenceUnitInformation(LogHelper.java:
Any idea why the error might occur?