Results 1 to 9 of 9

Thread: No bean named 'sessionFactory' is defined

  1. #1
    Join Date
    Aug 2007
    Posts
    7

    Default No bean named 'sessionFactory' is defined

    Kindl help me with the following error:
    I am using Struts,Spring and Hibernate.

    [8/29/07 17:15:30:531 IST] 00000027 WebApp E SRVE0026E: [Servlet Error]-[/UI/Common/Login.jsp]: org.springframework.beans.factory.NoSuchBeanDefini tionException: No bean named 'sessionFactory' is defined
    at org.springframework.beans.factory.support.DefaultL istableBeanFactory.getBeanDefinition(DefaultListab leBeanFactory.java:345)
    at org.springframework.beans.factory.support.Abstract BeanFactory.getMergedBeanDefinition(AbstractBeanFa ctory.java:894)
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:243)
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:164)
    at org.springframework.context.support.AbstractApplic ationContext.getBean(AbstractApplicationContext.ja va:707)
    at org.springframework.orm.hibernate3.support.OpenSes sionInViewFilter.lookupSessionFactory(OpenSessionI nViewFilter.java:243)
    at org.springframework.orm.hibernate3.support.OpenSes sionInViewFilter.lookupSessionFactory(OpenSessionI nViewFilter.java:227)
    at org.springframework.orm.hibernate3.support.OpenSes sionInViewFilter.doFilterInternal(OpenSessionInVie wFilter.java:171)
    at org.springframework.web.filter.OncePerRequestFilte r.doFilter(OncePerRequestFilter.java:75)
    at com.ibm.ws.webcontainer.filter.FilterInstanceWrapp er.doFilter(FilterInstanceWrapper.java:142)
    at com.ibm.ws.webcontainer.filter.WebAppFilterChain.d oFilter(WebAppFilterChain.java:77)
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.han dleRequest(ServletWrapper.java:626)
    at com.ibm.wsspi.webcontainer.servlet.GenericServletW rapper.handleRequest(GenericServletWrapper.java:11 7)
    at com.ibm.ws.jsp.webcontainerext.JSPExtensionServlet Wrapper.handleRequest(JSPExtensionServletWrapper.j ava:171)
    at com.ibm.ws.jsp.webcontainerext.JSPExtensionProcess or.handleRequest(JSPExtensionProcessor.java:230)
    at com.ibm.ws.webcontainer.webapp.WebApp.handleReques t(WebApp.java:2837)
    at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequ est(WebGroup.java:220)
    at com.ibm.ws.webcontainer.VirtualHost.handleRequest( VirtualHost.java:204)
    at com.ibm.ws.webcontainer.WebContainer.handleRequest (WebContainer.java:1681)
    at com.ibm.ws.webcontainer.channel.WCChannelLink.read y(WCChannelLink.java:77)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLi nk.handleDiscrimination(HttpInboundLink.java:421)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLi nk.handleNewInformation(HttpInboundLink.java:367)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLi nk.ready(HttpInboundLink.java:276)
    at com.ibm.ws.tcp.channel.impl.NewConnectionInitialRe adCallback.sendToDiscriminaters(NewConnectionIniti alReadCallback.java:201)
    at com.ibm.ws.tcp.channel.impl.NewConnectionInitialRe adCallback.complete(NewConnectionInitialReadCallba ck.java:103)
    at com.ibm.ws.tcp.channel.impl.WorkQueueManager.reque stComplete(WorkQueueManager.java:548)
    at com.ibm.ws.tcp.channel.impl.WorkQueueManager.attem ptIO(WorkQueueManager.java:601)
    at com.ibm.ws.tcp.channel.impl.WorkQueueManager.worke rRun(WorkQueueManager.java:934)
    at com.ibm.ws.tcp.channel.impl.WorkQueueManager$Worke r.run(WorkQueueManager.java:1021)
    at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.j ava:1332)

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,624

    Default

    Well what don't you understand about the errormessage

    Code:
    org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'sessionFactory' is defined
    There must be a bean named sessionFactory in your ApplicationContext if it isn't there (in 1 of your xml files) it cannot be found.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Aug 2007
    Posts
    7

    Default

    I am very new to Spring.
    Well here is the application context:
    Let me know what I am doing wrong.Thanx

    <beans>
    <bean id="pcrmDataSource"
    class="org.apache.commons.dbcp.BasicDataSource">
    <property name="driverClassName">
    <value>oracle.jdbc.driver.OracleDriver</value>
    </property>
    <property name="url">
    <value>jdbc:oracle:thin:@172.16.2.150:1521:orateng </value>
    </property>
    <property name="username">
    <value>PCRMDBNEW</value>
    </property>

    <property name="password">
    <value>PCRMDBNEW</value>
    </property>

    </bean>

    <bean id="pcrmHibernateProperties"
    class="org.springframework.beans.factory.config.Pr opertiesFactoryBean">
    <property name="properties">
    <props>
    <prop key="hibernate.hbm2ddl.auto">update</prop>
    <prop key="hibernate.dialect">
    org.hibernate.dialect.OracleDialect
    </prop>
    <prop key="hibernate.show_sql">true</prop>
    </props>
    </property>
    </bean>

    <bean id="pcrmSessionFactory"
    class="org.springframework.orm.hibernate3.LocalSes sionFactoryBean">
    <property name="dataSource">
    <ref local="pcrmDataSource" />
    </property>
    <property name="hibernateProperties">
    <ref bean="pcrmHibernateProperties" />
    </property>
    <!-- Must references all OR mapping files. -->
    <property name="mappingResources">
    <list>
    <value>com/pcrm/dao/hbm/producer/Company.hbm.xml</value>

    </list>
    </property>
    </bean>
    <!-- Pass the session factory to our UserDAO -->

    <bean id="companyDAO" class="com.pcrm.producer.dao.CompanyDAO">
    <property name="sessionFactory">
    <ref local="pcrmSessionFactory" />
    </property>
    </bean>

    <bean id="transactionManager"
    class="org.springframework.orm.hibernate3.Hibernat eTransactionManager">
    <property name="sessionFactory">
    <ref bean="pcrmSessionFactory" />
    </property>
    </bean>
    </beans>

  4. #4
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,624

    Default

    First when posting code please use the [ code][/code ] tags... It makes your post readable.

    You use the OpenSessionInViewFilter (as I see in your stacktrace) by default it looks for a bean named 'sessionFactory' your HibernateSessionFactory is called 'pcrmSessionFactory'. Specify the name on the OpenSessionInViewFilter (check the reference guide for more information).
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  5. #5
    Join Date
    Aug 2007
    Posts
    7

    Default

    Sorry for the inconvinience.

    This is what i have in my web.xml. Do I need to make anyother enteries in any other file.?

    Code:
    	<context-param>
    		<param-name>contextConfigLocation</param-name>
    		<param-value>
    			classpath*:PCRMSpring-config.xml,classpath*:PCRMHibernate-config.xml
    		</param-value>
    	</context-param>
    
    	<filter>
    		<filter-name>sessionFilter</filter-name>
    		<filter-class>
    			org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
    		</filter-class>
    	</filter>
    
    	<filter-mapping>
    		<filter-name>sessionFilter</filter-name>
    		<url-pattern>*.jsp</url-pattern>
    	</filter-mapping>
    
    	<listener>
    		<listener-class>
    			org.springframework.web.context.ContextLoaderListener
    		</listener-class>
    	</listener>
    thanks for your Time and help.

  6. #6
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,624

    Default

    Have you read the reference guide and javadoc for the OpenSessionInViewFilter and was my post that unclear?!

    However 2 solutions

    1) Rename your 'pcrmSessionFactory' to 'sessionFactrory'
    2) Add a filter init-property 'sessionFactoryBeanName', which references the correct sessionFacotry in your case 'pcrmSessionFactory', to your web.xml
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  7. #7
    Join Date
    Aug 2007
    Posts
    7

    Default

    I am getting the following error now:

    Code:
    [8/29/07 20:06:11:344 IST] 00000034 LazyInitializ E   could not initialize proxy - the owning Session was closed
    [8/29/07 20:06:11:359 IST] 00000034 LazyInitializ E   TRAS0014I: The following exception was logged org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed
    	at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:60)
    	at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:111)
    	at org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.invoke(CGLIBLazyInitializer.java:140)
    	at com.pcrm.dto.producer.CompanyDTO$$EnhancerByCGLIB$$897334c9.getName(<generated>)
    	at com.pcrm.producer.forms.section.CompanySBean.populateFormBean(CompanySBean.java:291)
    	at com.pcrm.producer.forms.section.AppointmentSBean.populateFormBean(AppointmentSBean.java:316)
    	at com.pcrm.framework.actions.PCRMBaseAction.replaceDTOWithFormBean(PCRMBaseAction.java:90)
    	at com.pcrm.producer.actions.DashBoardAction.execute(DashBoardAction.java:54)
    	at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
    	at com.pcrm.framework.controller.PCRMRequestProcessor.processActionPerform(PCRMRequestProcessor.java:96)
    	at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
    	at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
    	at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:763)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
    	at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1212)
    	at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:629)
    	at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:250)
    	at org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1069)
    	at org.apache.struts.tiles.TilesRequestProcessor.doForward(TilesRequestProcessor.java:274)
    	at org.apache.struts.action.RequestProcessor.processForwardConfig(RequestProcessor.java:455)
    	at org.apache.struts.tiles.TilesRequestProcessor.processForwardConfig(TilesRequestProcessor.java:320)
    	at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:279)
    	at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
    	at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:763)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
    	at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1212)
    	at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:629)
    	at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:2837)
    	at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:220)
    	at com.ibm.ws.webcontainer.VirtualHost.handleRequest(VirtualHost.java:204)
    	at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:1681)
    	at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:77)
    	at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:421)
    	at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewInformation(HttpInboundLink.java:367)
    	at com.ibm.ws.http.channel.inbound.impl.HttpICLReadCallback.complete(HttpICLReadCallback.java:94)
    	at com.ibm.ws.tcp.channel.impl.WorkQueueManager.requestComplete(WorkQueueManager.java:548)
    	at com.ibm.ws.tcp.channel.impl.WorkQueueManager.attemptIO(WorkQueueManager.java(Compiled Code))
    	at com.ibm.ws.tcp.channel.impl.WorkQueueManager.workerRun(WorkQueueManager.java:934)
    	at com.ibm.ws.tcp.channel.impl.WorkQueueManager$Worker.run(WorkQueueManager.java:1021)
    	at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java(Compiled Code))

  8. #8
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,624

    Default

    Use the search and search for lazy initialisation... A lot of posts cover that topic.

    Duplicate answers regarding that topic in there....
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  9. #9
    Join Date
    Aug 2010
    Posts
    1

    Default question

    i have the same question,the web.xml is not has question.
    The name of sessionFactory is right, but this question is not resolved.
    Hava any other question can lead to this condition?

Posting Permissions

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