org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'sessionFactory' is defined
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:360)
at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedBeanDefinition(AbstractBeanFactory.java:914)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:241)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:737)
at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.lookupSessionFactory(OpenSessionInViewFilter.java:243)
at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.lookupSessionFactory(OpenSessionInViewFilter.java:227)
at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:171)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:75)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:210)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:870)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:685)
at java.lang.Thread.run(Thread.java:619)看网上说是OpenSessionInViewFilter导致的  在web.xml 加人    
 
      <init-param>  
        <param-name>sessionFactoryBeanName</param-name>  
        <param-value>sessionFactory</param-value>  
    </init-param>还是不行  求各位GG JJ 帮忙看看到底什么原因? 给小弟指条明路

解决方案 »

  1.   

    建议备份当前的配置文件,然后删掉里面的所有bean的定义,重新一个个来,每配置一步,都运行一下以确定正确。
    No bean named 'sessionFactory' is defined 
    代表在配置文件中使用了当前位置之前从未定义过的bean。后面用到的bean的name,必定是前面定义过的,检查一下,这和open session in view没关系。
      

  2.   

    把配置也粘出来,可能HIBERNATE上在spring中没有配置正确,或者JAR包的路径等问题
      

  3.   

    你看看'sessionFactory' 大小写正确吗?也期待高手的参与!为楼主顶一下!
      

  4.   

    No bean named 'sessionFactory' 肯定是spring的配置文件如:applicationContext.xml,写错了
      

  5.   

    No bean named 'sessionFactory' is defined ,楼主你调试程序一定要看报错啊,一楼已经说放的很明白
      

  6.   

    看看在ServiceImpl里面有没有注入service
      

  7.   

    No bean named 'sessionFactory' is defined 
     spring 配sessionFactory了吗
      

  8.   

    sessionFactory能获得吗使用Struts作为action,当然就不需要使用Spring WEB framework,因此也不需要与之配套的配置文件例如,petstore-servlet.xml,
    还有remote-servlet.xml ,但是Spring仍旧加载此两个文件,没办法,只好将此两个文件挪动到别的地方,但是又出现找不到这两个
    文件的IO异常,没办法,只好又拷贝回来,然后把文件内容清掉
      

  9.   

     同意根本就没有找到'sessionFactory' 是你注入错了吧 不过也有可能你名字没有写对,建议配置文件中能Ctrl+c、v的不要自己手写,这样前后能保持一致,减少配置上不仔细造成的bug
      

  10.   

    spring配置文件配的有问题  sessionFactory 配置正确吗
      

  11.   

    在你的配置文件里面有错误是你的 sessionFactoryFactory没有被定义或者是你的那个或者是在配置时出了错误
      

  12.   

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
    <bean id="placeholderConfig"
    class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="locations">
    <list>
    <value>classpath:jdbc.properties</value>
    <value>classpath:config.properties</value>
    </list>
    </property>
    </bean> <bean id="myDataSource"
    class="com.mchange.v2.c3p0.ComboPooledDataSource"
    destroy-method="close" dependency-check="none">
    <property name="driverClass">
    <value>${datasource.driverClassName}</value>
    </property>
    <property name="jdbcUrl">
    <value>${datasource.url}</value>
    </property>
    <property name="user">
    <value>${datasource.username}</value>
    </property>
    <property name="password">
    <value>${datasource.password}</value>
    </property>
    <property name="acquireIncrement">
    <value>${c3p0.acquireIncrement}</value>
    </property>
    <property name="initialPoolSize">
    <value>${c3p0.initialPoolSize}</value>
    </property>
    <property name="minPoolSize">
    <value>${c3p0.minPoolSize}</value>
    </property>
    <property name="maxPoolSize">
    <value>${c3p0.maxPoolSize}</value>
    </property>
    <property name="maxIdleTime">
    <value>${c3p0.maxIdleTime}</value>
    </property>
    <property name="idleConnectionTestPeriod">
    <value>${c3p0.idleConnectionTestPeriod}</value>
    </property>
    <property name="maxStatements">
    <value>${c3p0.maxStatements}</value>
    </property>
    <property name="numHelperThreads">
    <value>${c3p0.numHelperThreads}</value>
    </property>
    </bean> <bean id="jdbcTemplate"
    class="org.springframework.jdbc.core.JdbcTemplate">
    <property name="dataSource">
    <ref bean="myDataSource" />
    </property>
    </bean> <bean id="mySessionFactory"
    class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
    <property name="dataSource">
    <ref local="myDataSource" />
    </property>
    <property name="mappingResources"> <list>
    <value>com/hxjr/oa/domain/TUser.hbm.xml</value>
    </list>
    </property>
    <property name="hibernateProperties">
    <props>
    <prop key="hibernate.dialect">
    ${hibernate.dialect}
    </prop>
    <prop key="hibernate.show_sql">
    ${hibernate.show_sql}
    </prop>
    <prop key="hibernate.jdbc.fetch_size">
    ${hibernate.jdbc.fetch_size}
    </prop> <prop key="hibernate.jdbc.batch_size">
    ${hibernate.jdbc.batch_size}
    </prop>
    <prop key="hibernate.connection.release_mode">
    ${hibernate.connection.release_mode}
    </prop>
    <prop key='hibernate.query.factory_class'>
    ${hibernate.query.factory_class}
    </prop>
    <prop key="hibernate.cache.provider_class">
    ${hibernate.cache.provider_class}
    </prop>
    <prop key="hibernate.cache.use_query_cache">
    ${hibernate.cache.use_query_cache}
    </prop>
    </props>
    </property>
    </bean> <bean id="myTransactionManager"
    class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    <property name="sessionFactory">
    <ref local="mySessionFactory" />
    </property>
    </bean> <bean id="myHibernateTemplate"
    class="org.springframework.orm.hibernate3.HibernateTemplate">
    <property name="sessionFactory">
    <ref bean="mySessionFactory" />
    </property>
    <property name="cacheQueries"
    value="${hibernate.cache.use_query_cache}">
    </property>
    </bean>
    <bean id="myTransactionProxyFactoryBean" lazy-init="true"
    class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
    <property name="transactionManager">
    <ref bean="myTransactionManager" />
    </property>
    <property name="transactionAttributes">
    <props>
    <prop key="save*">PROPAGATION_REQUIRED</prop>
    <prop key="copy*">PROPAGATION_REQUIRED</prop>
    <prop key="creat*">PROPAGATION_REQUIRED</prop>
    <prop key="check*">PROPAGATION_REQUIRED</prop>
    <prop key="update*">PROPAGATION_REQUIRED</prop>
    <prop key="delete*">PROPAGATION_REQUIRED</prop>
    <prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
    </props>
    </property>
    </bean> <import resource="config/server.xml" />
    <!--   <import resource="config/hr/applicationContext-orgManage.xml" />--></beans>我把sessionFactory 改成 mySessionFactory  后 有报 mySessionFactory
      

  13.   

    sessionFactory没有定义,你可以检查一下数据源的配置及bean之间的依赖关系是否正确!