Spring 5.0.7 With Hibernate 5.4.1 on resin server

485 Views Asked by At

This example is working fine in Tomcat9 with same jar but not working in Resin 4.0.61 Web server Configuration for Spring MVC in resin.xml file -

<servlet>
<servlet-name>springportfolio</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/springportfolio-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup></servlet>

<servlet-mapping>
<servlet-name>springportfolio</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>

springportfolio-servlet.xml configuration file-

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="
    http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context.xsd
    http://www.springframework.org/schema/mvc
    http://www.springframework.org/schema/mvc/spring-mvc.xsd
    http://www.springframework.org/schema/tx 
    http://www.springframework.org/schema/tx/spring-tx.xsd">

<!-- Add support for conversion, formatting and validation support -->
<mvc:annotation-driven />

<!-- Add support for component scanning -->
<context:component-scan
    base-package="com.example.portfolio" />

<!-- Define Spring MVC view resolver -->
<bean
    class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix"
        value="/web-inf/views/" />
    <property name="suffix" value=".jsp" />
</bean>

<!-- Step 1: Define Database DataSource / connection pool -->
<bean id="myDataSource"
    class="com.mchange.v2.c3p0.ComboPooledDataSource"
    destroy-method="close">
    <property name="driverClass"
        value="oracle.jdbc.driver.OracleDriver" />
    <property name="jdbcUrl"
        value="xxxxxx" />
    <property name="user" value="xxxx" />
    <property name="password" value="xxx" />

    <!-- these are connection pool properties for C3P0 -->
    <property name="minPoolSize" value="5" />
    <property name="maxPoolSize" value="20" />
    <property name="maxIdleTime" value="30000" />
</bean>

<!-- Step 2: Setup Hibernate session factory -->
<bean id="sessionFactory"
    class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
    <property name="dataSource" ref="myDataSource" />
    <property name="packagesToScan"
        value="com.example.portfolio.entity" />
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">org.hibernate.dialect.Oracle12cDialect</prop>
            <prop key="hibernate.show_sql">true</prop>
        </props>
    </property>
</bean>

<!-- Step 3: Setup Hibernate transaction manager -->
<bean id="myTransactionManager"
    class="org.springframework.orm.hibernate5.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory" />
</bean>

<!-- Step 4: Enable configuration of transactional behavior based on annotations -->
<tx:annotation-driven
    transaction-manager="myTransactionManager" />

Getting Exception - ERROR | Context initialization failed

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'customerController': Unsatisfied dependency expressed through field 'userService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userServiceImp': Unsatisfied dependency expressed through field 'userDao'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'customerDAOImpl': Unsatisfied dependency expressed through field 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/springportfolio-servlet.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: javax.persistence.Table.indexes()[Ljavax/persistence/Index;

1

There are 1 best solutions below

5
Michal On

Resin 4.0.61 conforms to JEE 6.0 specification. The JEE 6.0 includes JPA in version 2.0. According to the error message a JPA in version 2.1 is expected by the application. Either downgrade the application to JPA 2.0 or upgrade the server to JPA 2.1 as described in this forum