[opencms-dev] opencms + Spring + Session in View

jacek grzebyta (RRes-Roth) jacek.grzebyta at bbsrc.ac.uk
Tue Oct 5 18:00:28 CEST 2010


Hi guys,

I have just found problem with well known "LazyInitializationException". I did according google:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:context="http://www.springframework.org/schema/context"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">

<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
	<property name="prefix" value="/WEB-INF/external/"/>
	<property name="suffix" value=".jsp"/>
	<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
</bean>

<context:component-scan base-package="org.phibase.mvc.controllers"/>

<!-- Prepare interceptor for session in view pattern -->
 <bean id="sessionInterceptor" class="org.springframework.orm.hibernate3.support.OpenSessionInViewInterceptor">
	<property name="sessionFactory"><ref bean="phiSessionFactory"/></property>
	<property name="flushModeName" value="FLUSH_AUTO"/>
</bean> 

<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerExceptionResolver"/>

<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
	<property name="interceptors">
		<list>
			<ref local="sessionInterceptor"/>
		</list>
	</property>
</bean>

<bean id="adapter" class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"/>

</beans>

In controller I have:

	public class Gene {
		public String emblId;
		public Set<String> names;
	}
	
	
	@SuppressWarnings("unchecked")
	@RequestMapping("/test")
	public String getRefGenes(int test, ModelMap model) {
		log.debug("run test");
		
		model.addAttribute("test", test);
		// take all reference genes
		List<ReferencePhysicalGene> results = refGeneDAO.getAllItems();
		List<Gene> genes = new ArrayList<TestController.Gene>();

... load data from refGeneDAO to Set of local Gene class
		
... and finally save results to model
		model.addAttribute("genes", genes);
		
		log.debug("END");
		return "out";
	}

Further in JUnit test i have:
		MockHttpServletRequest request = new MockHttpServletRequest();
		request.setMethod("GET");
		request.setRequestURI("/test");
		request.setParameter("test", "10");
		request.setSession(new MockHttpSession()); ... just in any case :)
		
		MockHttpServletResponse response = new MockHttpServletResponse();
		final ModelAndView out = adapter.handle(request, response, controller);
		final Map<String, Object> model = out.getModel();

The error occurs in place where I get set of GeneNames from ref genes. Anyway this part work fine if i do just simple test on the dao directly with session binding to the thread. So it looks the interceptor doesn't work. How did you fixed it? Is it legal if I put the interceptor to DefaultAnnotationHandlerMapping?

Regards,
Jacek



More information about the opencms-dev mailing list