1

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;

Dev Singh
  • 11
  • 3
  • There must be an older JPA jar somewhere in the Resin 4.0.61 server. The older JPA specification does not have the indexes() method on the Table annotation causing this problem. Look for a jar named like *jpa-*.jar – Michal Mar 18 '19 at 10:13
  • What Spring and in particular Hibernate version are you using? The problem is that Resin 4.0.61 is JEE 6.0 server. That means, it brings JPA 2.0 with itselfs. Your spring application seems to require / expect JPA 2.1, that is the one including the JPA 2.1 API. Maybe it is possible to downgrade your spring / hibernate version to JPA 2.0 or to upgrade Resin to JPA 2.1 - see also https://groups.google.com/forum/#!msg/caucho-resin/divdHN_y2o4/gNPRITl9EQAJ – Michal Mar 18 '19 at 10:27

1 Answers1

0

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

Michal
  • 2,353
  • 1
  • 15
  • 18
  • I downgrade development to hibernate 5.2.17 support JPA in version 2.1 now how i can upgrade the server to JPA 2.1. This is what i did still getting same exception ` E:/WorkSpace/resin-4.0.61/lib/javax.servlet.jsp-api-2.3.1.jar ` – Dev Singh Mar 19 '19 at 09:16
  • javax.servlet.jsp-api-2.3.1.jar is the wrong jar. The correct jar needs to contain the annotation from the error message, i.e. javax.persistence.Table, and the annotations needs to have the indexes() method. Be aware that not only the JPA API jar needs to be added but the implementation jars too. – Michal Mar 19 '19 at 10:43
  • Now i am using hibernate-core implementation of the JPA specification and hibernate-jpa-2.1-api-1.0.0.Final.jar intended for use in developing Hibernate JPA implementation. ` /PATH/web-inf/lib/hibernate-jpa-2.1-api-1.0.0.Final.jar /PATH/web-inf/lib/hibernate-core-5.2.17.Final.jar ` Still getting same exception – Dev Singh Mar 20 '19 at 09:08
  • Is it exactly the same exception? Do you have possibility to debug in the Resin and see where it gets the javax.persistence.Table class from? I mean, from which jar? – Michal Mar 20 '19 at 16:26
  • Well, I am not expert on configuring the Resin server. Generally speaking, the Resin is not compatible with the application, that is for sure. If the Resin cannot be upgraded (JPA-wise) and the application cannot be downgraded to JPA 2.0 then my conclusion would be the application cannot run in that server. – Michal Mar 20 '19 at 16:29