gpt4 book ai didi

java - Spring MVC 4.0 - Web Config 中的 Hibernate OpenSessioninViewFilter

转载 作者:行者123 更新时间:2023-11-29 08:51:59 25 4
gpt4 key购买 nike

基本上,我该怎么做:

<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 模式。

提前致谢!

最佳答案

这就是我们所做的

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);
}
}

关于java - Spring MVC 4.0 - Web Config 中的 Hibernate OpenSessioninViewFilter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22367630/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com