I\'m a Spring newbie trying my first app. My hibernate gets closed before the view is rendered and having problems with lazy loaded properties (expected behavior). I\'ve added
To solve the problem in my case it was just missing this line
in the application-context file.
The @Transactional annotation over a method was not taken into account.
Hope it will help someone
My controllers where initialized twice, the same config was used by the root ApplicationContext and by the FrameworkServlet. I've had two contexts initialized. I've created a config for the root context named springapp.xml and moved all my middle tier configuration there and left my web tier configuration in springapp-servlet.xml
My web.xml now looks like this and everything works fine:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/springapp.xml
</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<filter>
<filter-name>hibernateFilter</filter-name>
<filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilter</filter-class>
<init-param>
<param-name>sessionFactoryBeanName</param-name>
<param-value>sessionFactory</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>hibernateFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
<servlet>
<servlet-name>springapp</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/springapp-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springapp</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>