Spring 3.2 + Hibernate 4 OpenSessionInViewFilter

前端 未结 2 1288
夕颜
夕颜 2021-02-03 13:57

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

2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-03 14:48

    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:

          
                contextConfigLocation
                
                    /WEB-INF/springapp.xml
            
            
    
         
                org.springframework.web.context.ContextLoaderListener
            
    
    
          hibernateFilter
          org.springframework.orm.hibernate4.support.OpenSessionInViewFilter
          
             sessionFactoryBeanName
             sessionFactory         
                
       
    
       
         hibernateFilter
        /*
        REQUEST
        FORWARD
        
    
        
            springapp
            org.springframework.web.servlet.DispatcherServlet
            
                    contextConfigLocation
                    /WEB-INF/springapp-servlet.xml
            
    
            1
          
    
    
    
          
            springapp
            /
          
    

提交回复
热议问题