异常:
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'sessionFactory' is defined (sessionFactory没有定义)
在web.xml中配置OpenSessionInViewFilter时应该指定SessionFactory的名字,配置如下:
<filter>
<filter-name>HibernateOpenSession</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
<init-param>
<param-name>sessionFactoryBeanName</param-name>
<param-value>mySessionFactory</param-value>
</init-param>
</filter>
Lazy问题可以通过加opensessioninviewfilter解决
在web.xml中加上
<filter>
<filter-name>openSessionInViewFilter</filter-name>
<filter-class>
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>openSessionInViewFilter</filter-name>
<url-pattern>*.do</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>openSessionInViewFilter</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>