Results 1 to 10 of 10

Thread: Error creating bean with name 'sessionFactory'

Hybrid View

  1. #1
    Join Date
    Dec 2005
    Posts
    8

    Default Error creating bean with name 'sessionFactory'

    Hi, I'm quite new in Spring and I've a little problem.
    When I try to run a test for my application it gives next error (like in title):
    Code:
    Exception in constructor: testSaveEmployee (org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [WEB-INF/applicationContext.xml]: Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: javax/transaction/TransactionManager java.lang.NoClassDefFoundError: javax/transaction/TransactionManager at java.lang.Class.getDeclaredMethods0(Native Method) at java.lang.Class.privateGetDeclaredMethods(Class.java:2365) at
    ...
    This is my applicationContext:

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
    	"http://www.springframework.org/dtd/spring-beans.dtd">
    
    <beans>
    	<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    		<property name="driverClassName"><value>com.mysql.jdbc.Driver</value></property>
    		<property name="url"><value>jdbc:mysql://localhost/employees</value></property>
    		<property name="username"><value>TestUser</value></property>
    		<property name="password"><value>test</value></property>
        </bean>
    	
    	<bean id="sessionFactory" class="org.springframework.orm.hibernate.LocalSessionFactoryBean">    
            <property name="dataSource">
            	<ref local="dataSource"/>
            </property>        
            <property name="mappingResources">
                <list>
                    <value>org/myemployees/model/Employee.hbm.xml</value>
                </list>
            </property>        
            <property name="hibernateProperties">
    	        <props>
    	            <prop key="hibernate.dialect">
    	            	net.sf.hibernate.dialect.MySQLDialect
    	            </prop>
    	            <prop key="hibernate.hbm2ddl.auto">update</prop>
    	        </props>
            </property>        
        </bean>
    	
        <bean id="transactionManager" class="org.springframework.orm.hibernate.HibernateTransactionManager">
            <property name="sessionFactory"><ref local="sessionFactory"/></property>
        </bean>
    	
    	<bean id="employeeDAO" class="org.myemployees.dao.hibernate.EmployeeDAOHibernate">
    		<property name="sessionFactory">
    			<ref local="sessionFactory" />
    		</property>
    	</bean>
    </beans>
    I really don't know what's wrong with this, it's almost the same as my sample app. (I rewrote it for learning reasons)
    ...

    Thanks in advance...
    Last edited by Emerxill; Jan 25th, 2006 at 07:58 AM.

  2. #2
    Join Date
    Aug 2004
    Posts
    2,715

    Default

    Looks like you need the jta.jar in your classpath. If you have the spring version with dependencies, you find this jar in the lib/j2ee subfolder.

    Regards,
    Andreas

  3. #3
    Join Date
    Dec 2005
    Posts
    8

    Default

    Ok that helped me some steps, there were some other jar's missing too.
    Thanks for the help.
    Now I am getting this error (I'm not sure it this is really a Spring problem...)
    Code:
    Exception in constructor: testSaveEmployee
    (org.springframework.beans.factory.BeanCreationException: Error creating
    bean with name 'sessionFactory' defined in class path resource
    [WEB-INF/applicationContext.xml]: Initialization of bean failed; nested
    exception is net.sf.hibernate.HibernateException: could not instantiate
    CacheProvider: net.sf.ehcache.hibernate.Provider
    net.sf.hibernate.HibernateException: could not instantiate CacheProvider:
    net.sf.ehcache.hibernate.Provider at
    net.sf.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:133)
    at net.sf.hibernate.cfg.Configuration.buildSettings(Configuration.java:1132)
    at
    net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:766)
    at
    org.springframework.orm.hibernate.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:544)
    at
    org.springframework.orm.hibernate.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:479)
    at
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1113)
    at
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:348)
    at
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:256)
    at
    org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:222)
    at
    org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:146)
    at
    org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:285)
    at
    org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:317)
    at
    org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:80)
    at
    org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:65)
    at 
    org.appfuse.dao.BaseDAOTestCase.<init>(BaseDAOTestCase.java:20)
    at
    org.appfuse.dao.EmployeeDAOTest.<init>(EmployeeDAOTest.java:6) at
    sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at
    sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    at
    sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:494) at
    junit.framework.TestSuite.createTest(TestSuite.java:131) at
    junit.framework.TestSuite.addTestMethod(TestSuite.java:114) at
    junit.framework.TestSuite.<init>(TestSuite.java:75) at
    org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:277)
    at
    org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.launch(JUnitTestRunner.java:672)
    at
    org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(JUnitTestRunner.java:567)
    Caused ...
    I would be very greatful if someone would help me with this one, cause I don't think I'm missing a jar here...

  4. #4
    Join Date
    Aug 2004
    Posts
    2,715

    Default

    Do you have the ehcache-1.1.jar in your classpath as well (from lib/ehcache)?

    Otherwise: Contains the original stacktrace further informations about a nested exception?

    Regards,
    Andreas

  5. #5
    Join Date
    Dec 2005
    Posts
    8

    Default

    Quote Originally Posted by Andreas Senft
    Do you have the ehcache-1.1.jar in your classpath as well (from lib/ehcache)?
    That was it
    Sorry for the stupid questions, but I'm reading a book (Spring Live) and I am trying to do the things explained myself but they don't mention the needed jars and such, they use an existing app and continue building and refactroring it... (maybe a bit further in the book but I don't have the patience )
    And I am also learning hibernate but I didn't get to far

    If you can advise me some good books, it's always welcome

    Thank you so much for the help so far, watch out for more

  6. #6
    Join Date
    Aug 2004
    Posts
    2,715

    Default

    Quote Originally Posted by Emerxill
    If you can advise me some good books, it's always welcome
    Concerning Spring there is a good overview here.

    As of hibernate I used the online reference and the forum so far.

    Regards,
    Andreas

  7. #7
    Join Date
    May 2011
    Location
    mumbai
    Posts
    37

    Default problem while instanitating bean

    Dear Andreas Senft plz help am also facing same issue...

    6:30:09,043 ERROR [ContextLoader] Context initialization failed
    org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'empJdbcTemplate' defined in class path resource [com/carrefour/fr/portail/carburant/emp/ejb-portail-carburant-emp-application-context.xml]: Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: org/springframework/jdbc/core/namedparam/SqlParameterSource
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.instantiateBean(Abstrac tAutowireCapableBeanFactory.java:883)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBeanInstance(Abst ractAutowireCapableBeanFactory.java:839)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.doCreateBean(AbstractAu towireCapableBeanFactory.java:440)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory$1.run(AbstractAutowireC apableBeanFactory.java:409)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:380)
    at org.springframework.beans.factory.support.Abstract BeanFactory$1.getObject(AbstractBeanFactory.java:2 64)
    at org.springframework.beans.factory.support.DefaultS ingletonBeanRegistry.getSingleton(DefaultSingleton BeanRegistry.java:222)
    at org.springframework.beans.factory.support.Abstract BeanFactory.doGetBean(AbstractBeanFactory.java:261 )
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:185)
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:164)
    at org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:429)
    at org.springframework.context.support.AbstractApplic ationContext.finishBeanFactoryInitialization(Abstr actApplicationContext.java:728)
    at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:380)
    at org.springframework.web.context.ContextLoader.crea teWebApplicationContext(ContextLoader.java:255)
    at org.springframework.web.context.ContextLoader.init WebApplicationContext(ContextLoader.java:199)
    at org.springframework.web.context.ContextLoaderListe ner.contextInitialized(ContextLoaderListener.java: 45)
    at org.apache.catalina.core.StandardContext.listenerS tart(StandardContext.java:3910)
    at org.apache.catalina.core.StandardContext.start(Sta ndardContext.java:4393)
    at org.jboss.web.tomcat.service.deployers.TomcatDeplo yment.performDeployInternal(TomcatDeployment.java: 310)
    at org.jboss.web.tomcat.service.deployers.TomcatDeplo yment.performDeploy(TomcatDeployment.java:142)
    at org.jboss.web.deployers.AbstractWarDeployment.star t(AbstractWarDeployment.java:461)
    at org.jboss.web.deployers.WebModule.startModule(WebM odule.java:118)
    at org.jboss.web.deployers.WebModule.start(WebModule. java:97)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknow n Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Un known Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.jboss.mx.interceptor.ReflectedDispatcher.invok e(ReflectedDispatcher.java:157)
    at org.jboss.mx.server.Invocation.dispatch(Invocation .java:96)
    at org.jboss.mx.server.Invocation.invoke(Invocation.j ava:88)
    at org.jboss.mx.server.AbstractMBeanInvoker.invoke(Ab stractMBeanInvoker.java:264)
    at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanSe rverImpl.java:668)
    at org.jboss.system.microcontainer.ServiceProxy.invok e(ServiceProxy.java:206)
    at $Proxy38.start(Unknown Source)
    at org.jboss.system.microcontainer.StartStopLifecycle Action.installAction(StartStopLifecycleAction.java :42)
    at org.jboss.system.microcontainer.StartStopLifecycle Action.installAction(StartStopLifecycleAction.java :37)
    at org.jboss.dependency.plugins.action.SimpleControll erContextAction.simpleInstallAction(SimpleControll erContextAction.java:62)
    at org.jboss.dependency.plugins.action.AccessControll erContextAction.install(AccessControllerContextAct ion.java:71)
    at org.jboss.dependency.plugins.AbstractControllerCon textActions.install(AbstractControllerContextActio ns.java:51)
    at org.jboss.dependency.plugins.AbstractControllerCon text.install(AbstractControllerContext.java:348)
    at org.jboss.system.microcontainer.ServiceControllerC ontext.install(ServiceControllerContext.java:286)
    at org.jboss.dependency.plugins.AbstractController.in stall(AbstractController.java:1631)
    at org.jboss.dependency.plugins.AbstractController.in crementState(AbstractController.java:934)
    at org.jboss.dependency.plugins.AbstractController.re solveContexts(AbstractController.java:1082)
    at org.jboss.dependency.plugins.AbstractController.re solveContexts(AbstractController.java:984)
    at org.jboss.dependency.plugins.AbstractController.ch ange(AbstractController.java:822)
    at org.jboss.dependency.plugins.AbstractController.ch ange(AbstractController.java:553)
    at org.jboss.system.ServiceController.doChange(Servic eController.java:688)
    at org.jboss.system.ServiceContro
    Last edited by junugari; May 4th, 2011 at 07:13 AM.

  8. #8
    Join Date
    Jun 2011
    Posts
    7

    Default

    Hello,

    I have the same Errors, but i can not find any solutions. Anyone can help me.

    org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'sessionFactory' defined in class path resource [Hibernate.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationExcepti on: Could not instantiate bean class [org.springframework.orm.hibernate3.LocalSessionFac toryBean]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.instantiateBean(Abstrac tAutowireCapableBeanFactory.java:883)

    i use Maven + Spring + Hibernate: This is my pom.xml. All libs i have already added.

    <dependencies>
    <dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>3.8.1</version>
    <scope>test</scope>
    </dependency>

    <!-- Spring framework -->
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring</artifactId>
    <version>2.5.6</version>
    </dependency>

    <!-- Spring AOP dependency -->
    <dependency>
    <groupId>cglib</groupId>
    <artifactId>cglib</artifactId>
    <version>2.2</version>
    </dependency>

    <!-- MySQL database driver -->
    <dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>5.1.9</version>
    </dependency>

    <!-- Hibernate framework -->
    <dependency>
    <groupId>hibernate</groupId>
    <artifactId>hibernate3</artifactId>
    <version>3.2.3.GA</version>
    </dependency>


    <!-- Hibernate library dependecy start -->
    <dependency>
    <groupId>dom4j</groupId>
    <artifactId>dom4j</artifactId>
    <version>1.6.1</version>
    </dependency>

    <dependency>
    <groupId>commons-logging</groupId>
    <artifactId>commons-logging</artifactId>
    <version>1.1.1</version>
    </dependency>

    <dependency>
    <groupId>commons-collections</groupId>
    <artifactId>commons-collections</artifactId>
    <version>3.2.1</version>
    </dependency>

    <dependency>
    <groupId>antlr</groupId>
    <artifactId>antlr</artifactId>
    <version>2.7.7</version>
    </dependency>
    <!-- Hibernate library dependecy end -->

    <dependency>
    <groupId>javax.validation</groupId>
    <artifactId>validation-api</artifactId>
    <version>1.0.0.GA</version>
    </dependency>
    <dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-validator</artifactId>
    <version>4.0.2.GA</version>
    </dependency>

    </dependencies>

  9. #9
    Join Date
    Nov 2011
    Posts
    1

    Default

    HI,

    I have the same error, i am looking for some suggestions on the this...

    [11/10/11 10:34:25:295 CST] 00000017 ServiceLogger I com.ibm.ws.ffdc.IncidentStreamImpl initialize FFDC0009I: FFDC opened incident stream file C:\USDADEV\IBM\SDP70\runtimes\base_v61\profiles\Ap pSrv11\logs\ffdc\server1_00000017_11.11.10_10.34.2 5_0.txt
    [11/10/11 10:34:25:498 CST] 00000017 ServiceLogger I com.ibm.ws.ffdc.IncidentStreamImpl resetIncidentStream FFDC0010I: FFDC closed incident stream file C:\USDADEV\IBM\SDP70\runtimes\base_v61\profiles\Ap pSrv11\logs\ffdc\server1_00000017_11.11.10_10.34.2 5_0.txt
    [11/10/11 10:34:25:498 CST] 00000017 WebApp E Exception caught while initializing context
    org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'sessionFactory' defined in URL [wsjar:file:/C:/Development/DLS-PLASTransactionMgr-ear-2.6.5/lib/dls-internal-common-1.4.5.jar!/session-factory-hibernate-cfg.spring.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: net.sf.cglib.proxy.CallbackFilter
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.initializeBean(Abstract AutowireCapableBeanFactory.java:1338)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.doCreateBean(AbstractAu towireCapableBeanFactory.java:473)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory$1.run(AbstractAutowireC apableBeanFactory.java:409)
    at java.security.AccessController.doPrivileged(Access Controller.java:215)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:380)
    at org.springframework.beans.factory.support.Abstract BeanFactory$1.getObject(AbstractBeanFactory.java:2 64)
    at org.springframework.beans.factory.support.DefaultS ingletonBeanRegistry.getSingleton(DefaultSingleton BeanRegistry.java:222)
    at org.springframework.beans.factory.support.Abstract BeanFactory.doGetBean(AbstractBeanFactory.java:261 )
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:185)
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:164)
    at org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:423)
    at org.springframework.context.support.AbstractApplic ationContext.finishBeanFactoryInitialization(Abstr actApplicationContext.java:728)
    at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:380)
    at org.springframework.web.context.ContextLoader.crea teWebApplicationContext(ContextLoader.java:255)
    at org.springframework.web.context.ContextLoader.init WebApplicationContext(ContextLoader.java:199)
    at org.springframework.web.context.ContextLoaderListe ner.contextInitialized(ContextLoaderListener.java: 45)
    at org.springframework.web.context.PlasTxMgrContextLo aderListener.contextInitialized(PlasTxMgrContextLo aderListener.java:13)
    at com.ibm.ws.wswebcontainer.webapp.WebApp.notifyServ letContextCreated(WebApp.java:645)
    at com.ibm.ws.webcontainer.webapp.WebApp.commonInitia lizationFinish(WebApp.java:311)
    at com.ibm.ws.wswebcontainer.webapp.WebApp.initialize (WebApp.java:290)
    at com.ibm.ws.wswebcontainer.webapp.WebGroup.addWebAp plication(WebGroup.java:90)
    at com.ibm.ws.wswebcontainer.VirtualHost.addWebApplic ation(VirtualHost.java:157)
    at com.ibm.ws.wswebcontainer.WebContainer.addWebApp(W ebContainer.java:665)
    at com.ibm.ws.wswebcontainer.WebContainer.addWebAppli cation(WebContainer.java:618)
    at com.ibm.ws.webcontainer.component.WebContainerImpl .install(WebContainerImpl.java:335)
    at com.ibm.ws.webcontainer.component.WebContainerImpl .start(WebContainerImpl.java:551)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •