错误No bean named 'sessionFactory' is defined

11-01-30 xiaofancn
我用S2SH整合,大部分用的是annotation注解。

org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'sessionFactory' is defined

org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:509)

org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1041)

org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:273)

org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)

org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1048)

org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.lookupSessionFactory(OpenSessionInViewFilter.java:242)

org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.lookupSessionFactory(OpenSessionInViewFilter.java:227)

org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:171)

org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)

以下是配置

=====================================applicationContext.xml

<bean id="sessionFactory"

class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean" >

<property name="dataSource">

<ref bean="dataSource" />

</property>

<property name="hibernateProperties">

<props>

<prop key="hibernate.dialect">

org.hibernate.dialect.MySQLDialect

</prop>

<prop key="hibernate.show_sql">true</prop>

</props>

</property>

<property name="annotatedClasses">

<list>

<value>org.snailteam.model.User</value>

</list>

</property>

</bean>

<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">

<property name="sessionFactory">

<ref local="sessionFactory" />

</property>

</bean>

===================web.xml

<filter>

<filter-name>lazyLoadingFilter</filter-name>

<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>

</filter>

<filter-mapping>

<filter-name>lazyLoadingFilter</filter-name>

<url-pattern>*.action</url-pattern>

</filter-mapping>

===============================测试代码成功

ApplicationContext ctx = new ClassPathXmlApplicationContext(

"applicationContext.xml");

UserAction uaction = (UserAction) ctx.getBean("userBean");

uaction.setUid(10);

uaction.get();

User u = uaction.getUser();

if(u!=null)

System.out.println(u.getName());

else

System.out.println("null");

xiaofancn
2011-01-30 22:12
一进行CRUD的操作,就报出上面的错误。求高手解答。

猜你喜欢