Recently, I have seen a sentence in zhihu. One of the ways to keep learning is that you have seen more cool people who are unwilling to do so.
When Spring and hibernate are integrated, jsp pages are displayed and the display attributes appear:
Org. apache. jasper. JasperException: cocould not initialize proxy-no Session-Class: org. hibernate. proxy. AbstractLazyInitializer
File: AbstractLazyInitializer. java
No session, lazy loading, adding an attribute such as name displayed on the jsp page is actually obtained using the getName method, but the session has been closed.
The solution is to write one more filter and the name is intuitive.
openSessionInview
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
openSessionInview
/*
When the session is opened at the presentation layer, it must be written before struts filtering. Because of the existence of the responsibility chain, it is first read but then implemented.
When I felt that there was no problem after the configuration, I found that sessionFactory was not injected, because the id of my sessionFactory was abbreviated to sf for me, and then I guess, it should be the OpenSessionInViewFilter class which needs to be injected with sessionFactory. This class also has the get method, but the name does not match, so the injection fails.
Try later
Of course not. I checked it later. The correct configuration is initialized in web. xml.
openSessionInview
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
sessionFactoryBeanName
sf
openSessionInview
/*
Finally, the name attribute is successfully displayed on the jsp page.