码迷,mamicode.com
首页 > 编程语言 > 详细

传统项目 升级到 spring boot 配置 org.springframework.orm.hibernate5.support.OpenSessionInViewFilter

时间:2020-10-22 22:35:08      阅读:26      评论:0      收藏:0      [点我收藏+]

标签:hiberna   cte   get   set   ONBUILD   send   vat   ida   ash   

OpenSessionInViewFilter (Spring Framework 5.2.9.RELEASE API)
https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/orm/hibernate5/support/OpenSessionInViewFilter.html

OpenSessionInViewInterceptor (Spring Framework 5.2.9.RELEASE API)
https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/orm/hibernate5/support/OpenSessionInViewInterceptor.html

org.springframework.orm.hibernate5.support (Spring Framework 5.2.9.RELEASE API)
https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/orm/hibernate5/support/package-summary.html

OpenSessionInViewFilter (Spring Framework API 2.5)
https://docs.spring.io/spring-framework/docs/2.5.4/javadoc-api/org/springframework/orm/hibernate3/support/OpenSessionInViewFilter.html

@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class,DataSourceTransactionManagerAutoConfiguration.class,JdbcTemplateAutoConfiguration.class,
FreeMarkerAutoConfiguration.class,ValidationAutoConfiguration.class,ServerPropertiesAutoConfiguration.class,MailSenderAutoConfiguration.class})
public class CrmApplication
{
public static void main(String[] args) {
SpringApplication.run(CrmApplication.class, args);
//configureApplication(new SpringApplicationBuilder()).run(args);
}

// @Override
// protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
// return configureApplication(builder);
// }

@Bean
public FilterRegistrationBean getHibernateOpenSessionInViewFilter() {

	FilterRegistrationBean hibernateOpenSessionInViewFilterRegistrationBean = new FilterRegistrationBean();

	hibernateOpenSessionInViewFilterRegistrationBean.setFilter(new OpenSessionInViewFilter());

	hibernateOpenSessionInViewFilterRegistrationBean.setEnabled(true);

	hibernateOpenSessionInViewFilterRegistrationBean.addUrlPatterns("*.do");
	hibernateOpenSessionInViewFilterRegistrationBean.addUrlPatterns("/rest/*");

	hibernateOpenSessionInViewFilterRegistrationBean.setInitParameters(new HashMap<String, String>() {
		private static final long serialVersionUID = -4377783733248874717L;
		{
			//put("sessionFactoryBeanName", "sessionFactory");

			put("singleSession", "true");

			//put("flushMode", "AUTO");
		}
	});

	hibernateOpenSessionInViewFilterRegistrationBean.setOrder(1);

	return hibernateOpenSessionInViewFilterRegistrationBean;
}

参考了如下代码:
hibernate - Using Spring Boot and Data JPA, getting LazyInitializationException despite the OpenSesionInViewFilter - Stack Overflow
https://stackoverflow.com/questions/36979281/using-spring-boot-and-data-jpa-getting-lazyinitializationexception-despite-the

传统项目 升级到 spring boot 配置 org.springframework.orm.hibernate5.support.OpenSessionInViewFilter

标签:hiberna   cte   get   set   ONBUILD   send   vat   ida   ash   

原文地址:https://www.cnblogs.com/rgqancy/p/13856607.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!