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

2021-03-23 04:25

阅读:370

标签: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() {
		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


评论


亲,登录后才可以留言!