2014-03-13 79 views
2

基本上,我怎麼可以這樣做:Spring MVC的4.0 - 休眠OpenSessionViewFilter在WebConfig

<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> 
WebInitializer

怎麼一回事,因爲如果寫:

@Override 
protected Filter[] getServletFilters() { 
    return new Filter[] { 
     new SpringSecurityFilterChain(), new OpenSessionViewFilter()  
    }; 
} 

不採取任何影響。

我認爲url-pattern缺失。

在此先感謝!

回答

0

這就是我們所做的

public class DispatcherServletInitializer 
    extends AbstractAnnotationConfigDispatcherServletInitializer { 

    @Override 
    public void onStartup(ServletContext servletContext) 
     throws ServletException { 
     servletContext 
     .addFilter("securityFilter", 
        new DelegatingFilterProxy("springSecurityFilterChain")) 
     .addMappingForUrlPatterns(null, false, "/*"); 

     //add other filters like this 
    super.onStartup(servletContext); 
    } 
} 
+1

你能解釋一下嗎? –