Announcement Announcement Module
Collapse
No announcement yet.
problem Spring+hibernate : can't generate bean name Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • problem Spring+hibernate : can't generate bean name

    Hi,
    I'm trying to use Spring with hibernate to access a database,
    I'm getting this:

    Code:
    org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unnamed bean definition specifies neither 'class' nor 'parent' nor 'factory-bean' - can't generate bean name
    Offending resource: ServletContext resource [/WEB-INF/applicationContext.xml]
    
    	at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:68)
    	at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:85)
    	at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:80)
    	at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.error(BeanDefinitionParserDelegate.java:314)
    	at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseBeanDefinitionElement(BeanDefinitionParserDelegate.java:497)
    	at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseBeanDefinitionElement(BeanDefinitionParserDelegate.java:440)
    	at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.processBeanDefinition(DefaultBeanDefinitionDocumentReader.java:315)
    	at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseDefaultElement(DefaultBeanDefinitionDocumentReader.java:206)
    	at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:185)
    	at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.doRegisterBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:144)
    	at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:114)
    	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:493)
    	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:390)
    	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334)
    	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
    	at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:174)
    	at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:209)
    	at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180)
    	at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:125)
    	at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:94)
    	at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:131)
    	at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:509)
    	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:427)
    	at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:294)
    	at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:215)
    	at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)
    	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4723)
    	at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5226)
    	at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5221)
    	at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
    	at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
    	at java.lang.Thread.run(Thread.java:619)
    here is the applicationContext.xml file

    Code:
    <?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:tx="http://www.springframework.org/schema/tx"
    	xsi:schemaLocation="
    		http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
    		http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
    
    	<!-- the data source class is recommend to use com.mchange.v2.c3p0.ComboPooledDataSource 
    		in production phase -->
    		
    	<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
    		destroy-method="close">
    		
    		<property name="driverClass" value="com.mysql.jdbc.Driver" />
    		<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/bdtest" />
    		<property name="user" value="root" />
    		<property name="password" value="" />
    	</bean>
    	
    	<!-- define Hibernate sessionFactory provided by Spring ORM -->
    	<bean id="sessionFactory"
    		class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    		<property name="dataSource" ref="dataSource" />
    		<!-- set other Hibernate properties in hibernate.cfg.xml file -->
    		<property name="configLocation" value="/WEB-INF/hibernate.cfg.xml" />
    	</bean>
    	
    	<!-- define Hibernate sessionFactory provided by Spring -->
    	<bean id="transactionManager"
    		class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    		<property name="sessionFactory" ref="sessionFactory" />
    	</bean>
    	
    	<!-- for using annotation @Transaction in DAOs -->
    	<tx:annotation-driven />
    	
    	<!-- inject relative DAO and Service beans -->
    	<bean id="companyDAO" class="org.zkoss.model.dao.CompanyDAO">
    		<property name="sessionFactory" ref="sessionFactory" />
    	</bean>
    	<bean id="companyManager" class="org.zkoss.service.CompanyManagerImpl">
    		<property name="companyDAO" ref="companyDAO" />
    	</bean>
    	
    	<bean id="userDAO" class="org.zkoss.model.dao.UserDAO">
    		<property name="sessionFactory" ref="sessionFactory" />
    	</bean>
    	<bean>
    		<property name="userDAO" ref="userDAO"></property>
    	</bean>
    	
    </beans>

    and hibernate.cfg.xml
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
                                             "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
    <hibernate-configuration>
    	<session-factory>
    		<!-- Database dialect -->
    		<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
    		
    		<!-- Echo all executed SQL to stdout -->
    		<property name="hibernate.show_sql">true</property>
    		<property name="hibernate.format_sql">true</property>
    		<property name="hibernate.current_session_context_class">thread</property>  
    		<property name="connection.pool_size">1</property>
    		<!-- mapping resources -->
    		<mapping package="org.zkoss.model.bean" />
    		<mapping class="org.zkoss.model.bean.Company" />
    		<mapping class="org.zkoss.model.bean.User" />
    		
    		<mapping resource="org\zkoss\model\bean\Company.hbm.xml" />
    		<mapping resource="org\zkoss\model\bean\User.hbm.xml"/>
    		
    	</session-factory>
    </hibernate-configuration>
    any suggestions please ..??

  • #2
    Am I missing sth in my configuration..
    I'm kind of lost and really nead your help ... please any sugestion could be helpful

    Comment


    • #3
      Hello Anna

      About this

      Code:
      <!-- inject relative DAO and Service beans -->
      	<bean id="companyDAO" class="org.zkoss.model.dao.CompanyDAO">
      		<property name="sessionFactory" ref="sessionFactory" />
      	</bean>
      	<bean id="companyManager" class="org.zkoss.service.CompanyManagerImpl">
      		<property name="companyDAO" ref="companyDAO" />
      	</bean>
      	
      	<bean id="userDAO" class="org.zkoss.model.dao.UserDAO">
      		<property name="sessionFactory" ref="sessionFactory" />
      	</bean>
      Be sure that each one be a concrete class not an implementation

      well the error is the follow

      Code:
      <bean>
      	<property name="userDAO" ref="userDAO"></property>
      </bean>
      Red part has no class attribute (id is optional if you want and anonymous class)

      Comment


      • #4
        thank you dr_pompeii
        I realized that the two classes were implementing the class "serializable", so I removed the implementation
        i also added

        <bean id="userManager" class="org.zkoss.service.UserManagerImpl">
        <property name="userDAO" ref="userDAO"></property>
        </bean>
        but it didn't work.

        so I just created a new project and moved all the packages and the configuration files into it .. then it works !!
        I still don't understand why my class (user) couldn't be found .. but i'm glad it's working now

        thanks again

        Regards

        Comment

        Working...
        X