Announcement Announcement Module
Collapse
No announcement yet.
Spring MVC + Hibernate Integration Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring MVC + Hibernate Integration

    I've been trying a lot but somehow not able to manage this error:

    --------------------------------------------------------------------------
    org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name '/hiberdata.htm' defined in ServletContext resource [/WEB-INF/springmvc-servlet.xml]: Cannot resolve reference to bean 'myUserDAO' while setting bean property 'userDAO'; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'myUserDAO' defined in ServletContext resource [/WEB-INF/springmvc-servlet.xml]: Cannot resolve reference to bean 'mySessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'mySessionFactory' defined in ServletContext resource [/WEB-INF/springmvc-servlet.xml]: Invocation of init method failed; nested exception is org.springframework.beans.BeanInstantiationExcepti on: Could not instantiate bean class [org.hibernate.cfg.AnnotationConfiguration]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: Could not initialize class org.hibernate.cfg.Environment
    org.springframework.beans.factory.support.BeanDefi nitionValueResolver.resolveReference(BeanDefinitio nValueResolver.java:328)
    org.springframework.beans.factory.support.BeanDefi nitionValueResolver.resolveValueIfNecessary(BeanDe finitionValueResolver.java:106)
    org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.applyPropertyValues(Abs tractAutowireCapableBeanFactory.java:1325)
    org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.populateBean(AbstractAu towireCapableBeanFactory.java:1086)
    org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.doCreateBean(AbstractAu towireCapableBeanFactory.java:517)
    org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:456)
    org.springframework.beans.factory.support.Abstract BeanFactory$1.getObject(AbstractBeanFactory.java:2 91)
    org.springframework.beans.factory.support.DefaultS ingletonBeanRegistry.getSingleton(DefaultSingleton BeanRegistry.java:222)
    org.springframework.beans.factory.support.Abstract BeanFactory.doGetBean(AbstractBeanFactory.java:288 )
    org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:190)
    org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:580)
    org.springframework.context.support.AbstractApplic ationContext.finishBeanFactoryInitialization(Abstr actApplicationContext.java:895)
    org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:425)
    org.springframework.web.servlet.FrameworkServlet.c reateWebApplicationContext(FrameworkServlet.java:4 42)
    org.springframework.web.servlet.FrameworkServlet.c reateWebApplicationContext(FrameworkServlet.java:4 58)
    org.springframework.web.servlet.FrameworkServlet.i nitWebApplicationContext(FrameworkServlet.java:339 )
    org.springframework.web.servlet.FrameworkServlet.i nitServletBean(FrameworkServlet.java:306)
    org.springframework.web.servlet.HttpServletBean.in it(HttpServletBean.java:127)
    javax.servlet.GenericServlet.init(GenericServlet.j ava:212)
    org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:102)
    org.apache.catalina.connector.CoyoteAdapter.servic e(CoyoteAdapter.java:293)
    org.apache.coyote.http11.Http11Processor.process(H ttp11Processor.java:849)
    org.apache.coyote.http11.Http11Protocol$Http11Conn ectionHandler.process(Http11Protocol.java:583)
    org.apache.tomcat.util.net.JIoEndpoint$Worker.run( JIoEndpoint.java:454)
    java.lang.Thread.run(Thread.java:619)
    --------------------------------------------------------------------------

    I'm using spring 3.5 + hibernate 3 + tomcat6 + jdk1.6

    Here is my springmvc-servlet.xml

    -------------------------------------------------------------------------
    <?xml version="1.0" encoding="UTF-8"?>

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

    <bean name="/addannot.htm" class="pack.AddAnnotController"/>
    <bean name="/index.htm" class="pack.SimpleController"/>
    <bean name="/data.htm" class="pack.DataController"/>
    <bean name="/singledata.htm" class="pack.SingleDataController"/>
    <bean name="/hiberdata.htm" class="pack.UserController">
    <property name="userDAO" ref="myUserDAO" />
    </bean>

    <bean id="userValidator" class="pack.UserValidator" />
    <bean id="messageSource" class="org.springframework.context.support.Resourc eBundleMessageSource" p:basename="messages" />

    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
    <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
    <property name="url" value="jdbc:mysql://localhost:3306/spring"/>
    <property name="username" value="spring"/>
    <property name="password" value="spring"/>
    </bean>

    <bean id="mySessionFactory" class="org.springframework.orm.hibernate3.annotati on.AnnotationSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />

    <property name="annotatedClasses">
    <list>
    <value>hiber.User</value>
    </list>
    </property>

    <property name="hibernateProperties">
    <props>
    <prop key="hibernate.dialect"> org.hibernate.dialect.MySQLDialect</prop>
    <prop key="hibernate.show_sql">true</prop>
    <prop key="hibernate.hbm2ddl.auto">create</prop>
    </props>
    </property>
    </bean>

    <bean id="myUserDAO" class="hiber.UserDAOImpl">
    <property name="sessionFactory" ref="mySessionFactory"/>
    </bean>

    <context:component-scan base-package="pack">
    <context:include-filter type="annotation" expression="org.springframework.stereotype.Control ler"/>
    </context:component-scan>

    <!-- ****************************Login form controllers**************************** -->
    <!-- use this below to move to a jsp <property name="successView" value="welcome"/> -->

    <!-- Page Controller -->
    <bean name="/login.htm" class="pack.LoginController">
    <property name="validator">
    <bean class="pack.LoginFormValidator"/>
    </property>
    <property name="formView" value="loginform"/>
    <property name="successView" value="data.htm"/>
    <property name="commandName" value="loginForm"/>
    <property name="commandClass" value="pack.LoginForm"/>
    </bean>

    <bean id="resultPageController" class="pack.ResultPageController"></bean>

    <!-- ****************************Login form controllers**************************** -->

    <bean class="org.springframework.web.servlet.view.Intern alResourceViewResolver">
    <property name="prefix"><value>/WEB-INF/jsp/</value></property>
    <property name="suffix"><value>.jsp</value></property>
    <property name="viewClass">
    <value>org.springframework.web.servlet.view.JstlVi ew</value>
    </property>
    </bean>

    </beans>
    -------------------------------------------------------------------------

    I've placed all the required jars in 'lib' directory of my web application and double checked database settings, but still i get this error


    Please, somebody tell me what's i'm doing wrong

  • #2
    hello ashutosh,

    i am beginner for hybernate and spring,
    i have the same problem here if u have found solution then plz tell me what to do to solve this problem.


    exception
    ================================================== ======
    javax.servlet.ServletException: Servlet.init() for servlet dispatcher threw exception
    org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:102)
    org.apache.catalina.connector.CoyoteAdapter.servic e(CoyoteAdapter.java:286)
    org.apache.coyote.http11.Http11Processor.process(H ttp11Processor.java:845)
    org.apache.coyote.http11.Http11Protocol$Http11Conn ectionHandler.process(Http11Protocol.java:583)
    org.apache.tomcat.util.net.JIoEndpoint$Worker.run( JIoEndpoint.java:447)
    java.lang.Thread.run(Unknown Source)


    root cause

    org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'mySessionFactory' defined in ServletContext resource [/WEB-INF/dispatcher-servlet.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchFieldError: tableNameBinding
    org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.initializeBean(Abstract AutowireCapableBeanFactory.java:1337)
    org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.doCreateBean(AbstractAu towireCapableBeanFactory.java:476)
    org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory$1.run(AbstractAutowireC apableBeanFactory.java:412)
    java.security.AccessController.doPrivileged(Native Method)
    org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:383)
    org.springframework.beans.factory.support.Abstract BeanFactory$1.getObject(AbstractBeanFactory.java:2 76)
    org.springframework.beans.factory.support.DefaultS ingletonBeanRegistry.getSingleton(DefaultSingleton BeanRegistry.java:222)
    org.springframework.beans.factory.support.Abstract BeanFactory.doGetBean(AbstractBeanFactory.java:273 )
    org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:175)
    org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:479)
    org.springframework.context.support.AbstractApplic ationContext.finishBeanFactoryInitialization(Abstr actApplicationContext.java:716)
    org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:377)
    org.springframework.web.servlet.FrameworkServlet.c reateWebApplicationContext(FrameworkServlet.java:4 27)
    org.springframework.web.servlet.FrameworkServlet.i nitWebApplicationContext(FrameworkServlet.java:341 )
    org.springframework.web.servlet.FrameworkServlet.i nitServletBean(FrameworkServlet.java:307)
    org.springframework.web.servlet.HttpServletBean.in it(HttpServletBean.java:127)
    javax.servlet.GenericServlet.init(GenericServlet.j ava:212)
    org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:102)
    org.apache.catalina.connector.CoyoteAdapter.servic e(CoyoteAdapter.java:286)
    org.apache.coyote.http11.Http11Processor.process(H ttp11Processor.java:845)
    org.apache.coyote.http11.Http11Protocol$Http11Conn ectionHandler.process(Http11Protocol.java:583)
    org.apache.tomcat.util.net.JIoEndpoint$Worker.run( JIoEndpoint.java:447)
    java.lang.Thread.run(Unknown Source)


    root cause

    java.lang.NoSuchFieldError: tableNameBinding
    org.hibernate.cfg.AnnotationConfiguration.createEx tendedMappings(AnnotationConfiguration.java:166)
    org.hibernate.cfg.AnnotationConfiguration.secondPa ssCompile(AnnotationConfiguration.java:254)
    org.hibernate.cfg.Configuration.buildMappings(Conf iguration.java:970)
    org.springframework.orm.hibernate3.LocalSessionFac toryBean.buildSessionFactory(LocalSessionFactoryBe an.java:667)
    org.springframework.orm.hibernate3.AbstractSession FactoryBean.afterPropertiesSet(AbstractSessionFact oryBean.java:211)
    org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.invokeInitMethods(Abstr actAutowireCapableBeanFactory.java:1368)
    org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.initializeBean(Abstract AutowireCapableBeanFactory.java:1334)
    org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.doCreateBean(AbstractAu towireCapableBeanFactory.java:476)
    org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory$1.run(AbstractAutowireC apableBeanFactory.java:412)
    java.security.AccessController.doPrivileged(Native Method)
    org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:383)
    org.springframework.beans.factory.support.Abstract BeanFactory$1.getObject(AbstractBeanFactory.java:2 76)
    org.springframework.beans.factory.support.DefaultS ingletonBeanRegistry.getSingleton(DefaultSingleton BeanRegistry.java:222)
    org.springframework.beans.factory.support.Abstract BeanFactory.doGetBean(AbstractBeanFactory.java:273 )
    org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:175)
    org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:479)
    org.springframework.context.support.AbstractApplic ationContext.finishBeanFactoryInitialization(Abstr actApplicationContext.java:716)
    org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:377)
    org.springframework.web.servlet.FrameworkServlet.c reateWebApplicationContext(FrameworkServlet.java:4 27)
    org.springframework.web.servlet.FrameworkServlet.i nitWebApplicationContext(FrameworkServlet.java:341 )
    org.springframework.web.servlet.FrameworkServlet.i nitServletBean(FrameworkServlet.java:307)
    org.springframework.web.servlet.HttpServletBean.in it(HttpServletBean.java:127)
    javax.servlet.GenericServlet.init(GenericServlet.j ava:212)
    org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:102)
    org.apache.catalina.connector.CoyoteAdapter.servic e(CoyoteAdapter.java:286)
    org.apache.coyote.http11.Http11Processor.process(H ttp11Processor.java:845)
    org.apache.coyote.http11.Http11Protocol$Http11Conn ectionHandler.process(Http11Protocol.java:583)
    org.apache.tomcat.util.net.JIoEndpoint$Worker.run( JIoEndpoint.java:447)
    java.lang.Thread.run(Unknown Source)
    ================================================== ========

    my dispatcher-servlet is:

    ===============================================
    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://www.springframework.org/schema/p"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/b ... -beans.xsd">

    <bean id="viewResolver" class="org.springframework.web.servlet.view.Intern alResourceViewResolver" prefix="/WEB-INF/jsp/" p:suffix=".jsp" />

    <bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
    <property name="driverClassName" value="org.hsqldb.jdbcDriver"/>
    <property name="url" value="jdbc:hsqldb:hsql://localhost:9001"/>
    <property name="username" value="sa"/>
    <property name="password" value=""/>
    </bean>

    <bean id="mySessionFactory" class="org.springframework.orm.hibernate3.annotati on.AnnotationSessionFactoryBean">
    <property name="dataSource" ref="myDataSource" />
    <property name="annotatedClasses">
    <list>
    <value>com.omni.domain.User</value>
    </list>
    </property>


    <property name="hibernateProperties">
    <props>
    <prop key="hibernate.dialect">org.hibernate.dialect.HSQL Dialect</prop>
    <prop key="hibernate.show_sql">true</prop>
    <prop key="hibernate.hbm2ddl.auto">create</prop>
    </props>
    </property>
    </bean>


    <bean id="myUserDAO" class="com.omni.dao.UserDAOImpl">
    <property name="sessionFactory" ref="mySessionFactory"/>
    </bean>

    <bean name="/user/*.htm" class="com.omni.web.UserController" >
    <property name="userDAO" ref="myUserDAO" />
    </bean>
    ================================================== ==============

    plz somebody help me for teh same.

    Comment


    • #3
      Hi ashutoshpandey,

      nested exception is java.lang.NoClassDefFoundError: Could not initialize class org.hibernate.cfg.Environment
      Hibernate seems to be missing on your classpath.

      Comment


      • #4
        Hi pramod.gaikwad

        google is great isn't it ? If you search for 'tableNameBinding' you'll find this:
        https://forum.hibernate.org/viewtopic.php?f=9&t=956020

        happy coding

        Andreas

        Comment


        • #5
          thank you for ur reply Andreas.

          its all about jar file conflicts, problem has been solved.

          ----
          pramod

          Comment

          Working...
          X