Announcement Announcement Module
Collapse
No announcement yet.
standalone spring app, exception loading context from xml file Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • standalone spring app, exception loading context from xml file

    im trying to just up an application context file using the FileSystemXmlApplicationContext object, but im getting a stacktrace when it tries to load my LocalSessionFactoryBean.
    Code:
     
    <bean id="myDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
    <property name="driverClass" value="com.mysql.jdbc.Driver" />
    <property name="jdbcUrl" value="dbc:mysql://localhost:3306/gsdb?autoReconnect=true" />
    <property name="user" value="root" />
    <property name="password" value="asdf" />
    </bean>
    
     
    <bean id="mySessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
            <property name="dataSource" ref="myDataSource" />
            <property name="mappingResources">
                <list>
                    <value>blah.hbm.xml</value>    
                </list>
            </property>
            <property name="hibernateProperties">
                <value>hibernate.dialect=org.hibernate.dialect.MySQLInnoDBDialect</value>
            </property>
        </bean>

    Code:
    INFO: Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@29ac: defining beans [myDataSource,mySessionFactory,userDao]; root of factory hierarchy
    Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mySessionFactory' defined in file [C:\myWorkspace\myapp\war\WEB-INF\daoContext.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.orm.hibernate3.LocalSessionFactoryBean]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/dom4j/DocumentException
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:883)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:839)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:440)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
    	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
    	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:221)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:423)
    	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:729)
    	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:381)
    	at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:140)
    	at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:94)
    	at myapp.dbcontrol.TableCreater.create(TableCreater.java:37)
    	at myapp.dbcontrol.TableCreater.main(TableCreater.java:27)
    Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.orm.hibernate3.LocalSessionFactoryBean]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/dom4j/DocumentException
    	at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:115)
    	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:61)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:877)
    	... 17 more
    Caused by: java.lang.NoClassDefFoundError: org/dom4j/DocumentException
    	at java.lang.Class.forName0(Native Method)
    	at java.lang.Class.forName(Unknown Source)
    	at org.springframework.orm.hibernate3.LocalSessionFactoryBean.class$(LocalSessionFactoryBean.java:174)
    	at org.springframework.orm.hibernate3.LocalSessionFactoryBean.<init>(LocalSessionFactoryBean.java:174)
    	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    	at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    	at java.lang.reflect.Constructor.newInstance(Unknown Source)
    	at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:100)
    	... 19 more

  • #2
    The error appears to be caused by a missing jar file in your classpath:

    Code:
    Caused by: java.lang.NoClassDefFoundError: org/dom4j/DocumentException
    Hibernate has some dependencies on dom4j.

    Comment


    • #3
      okay i copied all the files from hibernate distribution's required lib folder... then it complains about lacking slf4j's StaticLoggerBinder, so i did some research and found that i should be including slf4j-simple in addition to the slf4j-api which was in the hibernate required lib folder. its strange that the hibernate team did not include this file in their distribution?

      Comment


      • #4
        now im getting the following exception:
        Code:
        : Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.orm.hibernate3.LocalSessionFactoryBean]: Constructor threw exception; nested exception is java.lang.NoSuchFieldError: name

        Comment


        • #5
          Try to use the <props> element:

          Code:
          ....
          <property name="hibernateProperties">
            <props>
          	<prop key="hibernate.dialect">${hibernate.dialect}</prop>
          	<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
          	<prop key="hibernate.generate_statistics">${hibernate.generate_statistics}</prop>
            </props>
          ....

          Comment


          • #6
            tried changing it to
            Code:
                    <property name="hibernateProperties">
                        <props>
                        	<prop key="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</prop>
                   		 </props>
                     </property>
            but same error occurs

            Comment


            • #7
              any ideas?

              Comment


              • #8
                Can you post full stck trace?
                Originally posted by ew0kian View Post
                any ideas?

                Comment


                • #9
                  Code:
                  Sep 17, 2008 1:23:24 AM org.springframework.context.support.AbstractApplicationContext prepareRefresh
                  INFO: Refreshing org.springframework.context.support.FileSystemXmlApplicationContext@ec16a4: display name [org.springframework.context.support.FileSystemXmlApplicationContext@ec16a4]; startup date [Wed Sep 17 01:23:24 CDT 2008]; root of context hierarchy
                  Sep 17, 2008 1:23:24 AM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
                  INFO: Loading XML bean definitions from file [C:\myWorkspace\myapp\war\WEB-INF\applicationContext.xml]
                  Sep 17, 2008 1:23:24 AM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
                  INFO: Loading XML bean definitions from file [C:\myWorkspace\myapp\war\WEB-INF\daoContext.xml]
                  Sep 17, 2008 1:23:25 AM org.springframework.context.support.AbstractApplicationContext obtainFreshBeanFactory
                  INFO: Bean factory for application context [org.springframework.context.support.FileSystemXmlApplicationContext@ec16a4]: org.springframework.beans.factory.support.DefaultListableBeanFactory@1e04cbf
                  Sep 17, 2008 1:23:25 AM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
                  INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@1e04cbf: defining beans [myDataSource,mySessionFactory]; root of factory hierarchy
                  Sep 17, 2008 1:23:25 AM com.mchange.v2.log.MLog <clinit>
                  INFO: MLog clients using java 1.4+ standard logging.
                  Sep 17, 2008 1:23:25 AM com.mchange.v2.c3p0.C3P0Registry banner
                  INFO: Initializing c3p0-0.9.1.2 [built 21-May-2007 15:04:56; debug? true; trace: 10]
                  Sep 17, 2008 1:23:25 AM org.springframework.beans.factory.support.DefaultSingletonBeanRegistry destroySingletons
                  INFO: Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@1e04cbf: defining beans [myDataSource,mySessionFactory]; root of factory hierarchy
                  Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mySessionFactory' defined in file [C:\myWorkspace\myapp\war\WEB-INF\daoContext.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.orm.hibernate3.LocalSessionFactoryBean]: Constructor threw exception; nested exception is java.lang.NoSuchFieldError: name
                  	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:883)
                  	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:839)
                  	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:440)
                  	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
                  	at java.security.AccessController.doPrivileged(Native Method)
                  	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
                  	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
                  	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:221)
                  	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
                  	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
                  	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
                  	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:423)
                  	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:729)
                  	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:381)
                  	at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:140)
                  	at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:94)
                  	at myapp.dbcontrol.TableCreater.create(TableCreater.java:35)
                  	at myapp.dbcontrol.TableCreater.main(TableCreater.java:26)
                  Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.orm.hibernate3.LocalSessionFactoryBean]: Constructor threw exception; nested exception is java.lang.NoSuchFieldError: name
                  	at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:115)
                  	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:61)
                  	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:877)
                  	... 17 more
                  Caused by: java.lang.NoSuchFieldError: name
                  	at org.slf4j.impl.SimpleLogger.<init>(SimpleLogger.java:83)
                  	at org.slf4j.impl.SimpleLoggerFactory.getLogger(SimpleLoggerFactory.java:67)
                  	at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:103)
                  	at org.hibernate.cfg.Configuration.<clinit>(Configuration.java:128)
                  	at java.lang.Class.forName0(Native Method)
                  	at java.lang.Class.forName(Unknown Source)
                  	at org.springframework.orm.hibernate3.LocalSessionFactoryBean.class$(LocalSessionFactoryBean.java:174)
                  	at org.springframework.orm.hibernate3.LocalSessionFactoryBean.<init>(LocalSessionFactoryBean.java:174)
                  	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
                  	at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
                  	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
                  	at java.lang.reflect.Constructor.newInstance(Unknown Source)
                  	at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:100)
                  	... 19 more

                  Comment


                  • #10
                    Originally posted by ew0kian View Post
                    any ideas?
                    I have similar error with spring-framework-2.5.3 and hibernate-3.3.1.GA
                    While I can not understand why the problem occurs.
                    Can anyone help me find the cause of the error?

                    Code:
                    2008-09-16 18:47:21,084 ERROR [org.springframework.web.context.ContextLoader] - Context initialization failed
                    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'josService' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Cannot create inner bean 'mejos.domain.service.JosServiceImpl#1e5bbb0' of type [mejos.domain.service.JosServiceImpl] while setting bean property 'target'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mejos.domain.service.JosServiceImpl#1e5bbb0' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Cannot resolve reference to bean 'domainDao' while setting bean property 'domainDao'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'domainDao' defined in ServletContext resource [/WEB-INF/dataAccessContext-hibernate.xml]: Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/dataAccessContext-hibernate.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.orm.hibernate3.LocalSessionFactoryBean]: Constructor threw exception; nested exception is java.lang.NoSuchFieldError: name
                    	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:230)
                    	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:117)
                    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1244)
                    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1008)
                    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:470)
                    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
                    	at java.security.AccessController.doPrivileged(Native Method)
                    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
                    	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
                    	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:217)
                    	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
                    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
                    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
                    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:423)
                    	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:729)
                    	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:381)
                    	at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:255)
                    	at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:199)
                    	at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:45)
                    	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3843)
                    	at org.apache.catalina.core.StandardContext.start(StandardContext.java:4350)
                    	at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
                    	at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
                    	at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)
                    	at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:626)
                    	at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:553)
                    	at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:488)
                    	at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1215)
                    	at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:293)
                    	at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
                    	at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1337)
                    	at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1601)
                    	at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1610)
                    	at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1590)
                    	at java.lang.Thread.run(Thread.java:619)

                    Comment


                    • #11
                      Originally posted by ew0kian View Post
                      Code:
                      ...
                      org.slf4j.impl.SimpleLoggerFactory.getLogger(SimpleLoggerFactory.java:67)
                      	at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:103)
                      	at org.hibernate.cfg.Configuration.<clinit>(Configuration.java:128)
                      	at java.lang.Class.forName0(Native Method)
                      	at java.lang.Class.forName(Unknown Source)
                      ...
                      I have fixed it!
                      My problem was due to incompatible versions of the components of the slf4j library.
                      The project used the following:
                      slf4j-api-1.5.2.jar
                      slf4j-log4j12-1.5.3.jar
                      but they aren't compatible.

                      slf4j-api-1.5.2.jar was replaced by slf4j-api-1.5.3.jar and now it works!

                      Comment


                      • #12
                        cool nice work. i replaced slf4j-api-1.4.2 with slf4j-api-1.5.3 and now it works. do you know if it matters if i use slf4j-simple or slf4j-log4j12?

                        Comment


                        • #13
                          I had this error
                          java.lang.NoSuchFieldError: name
                          until I matched all of my libraries for slf4j to the latest release the
                          .name field was added in a new (recent) superclass and the java.lang error
                          is that there really isn't such a field in the class defintion.

                          I'd check the mix and match of version of all of the slf4j and any other sets
                          of libraries because you have a .class that actually says this.name and
                          there isn't such a field in the classes you have brought together.

                          Comment


                          • #14
                            right, i made sure those two have the same version number and it works fine now

                            Comment


                            • #15
                              I am getting the exact same error.

                              Caused by: java.lang.NoSuchFieldError: name
                              at org.slf4j.impl.SimpleLogger.<init>(SimpleLogger.ja va:83)
                              at org.slf4j.impl.SimpleLoggerFactory.getLogger(Simpl eLoggerFactory.java:67)
                              at org.slf4j.LoggerFactory.getLogger(LoggerFactory.ja va:103)
                              at org.hibernate.cfg.Configuration.<clinit>(Configura tion.java:151)
                              at org.hibernate.ejb.Ejb3Configuration.<clinit>(Ejb3C onfiguration.java:107)
                              at org.hibernate.ejb.HibernatePersistence.createConta inerEntityManagerFactory(HibernatePersistence.java :130)
                              at org.springframework.orm.jpa.LocalContainerEntityMa nagerFactoryBean.createNativeEntityManagerFactory( LocalContainerEntityManagerFactoryBean.java:221)
                              at org.springframework.orm.jpa.AbstractEntityManagerF actoryBean.afterPropertiesSet(AbstractEntityManage rFactoryBean.java:251)
                              at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.invokeInitMethods(Abstr actAutowireCapableBeanFactory.java:1390)
                              at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.initializeBean(Abstract AutowireCapableBeanFactory.java:1359)

                              Comment

                              Working...
                              X