Java Code Examples for org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter

The following examples show how to use org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: inception   Source File: InceptionWebInitializer.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void onStartup(ServletContext aServletContext) throws ServletException
{
    // 2) Make username accessible to logging framework
    FilterRegistration loggingFilter = aServletContext.addFilter("logging",
            LoggingFilter.class);
    loggingFilter.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), false, "/*");

    // 5) Make sure we have one JPA session/transaction per request. Closes session at the
    // end, without this, changed data may not be automatically saved to the DB.
    FilterRegistration openSessionInViewFilter = aServletContext.addFilter("opensessioninview",
            OpenEntityManagerInViewFilter.class);
    openSessionInViewFilter.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), false,
            "/*");
    
    aServletContext.addListener(HttpSessionEventPublisher.class);
}
 
Example 2
Source Project: webanno   Source File: WebAnnoWebInitializer.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void onStartup(ServletContext aServletContext) throws ServletException
{
    // 2) Make username accessible to logging framework
    FilterRegistration loggingFilter = aServletContext.addFilter("logging",
            LoggingFilter.class);
    loggingFilter.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), false, "/*");

    // 5) Make sure we have one JPA session/transaction per request. Closes session at the
    // end, without this, changed data may not be automatically saved to the DB.
    FilterRegistration openSessionInViewFilter = aServletContext.addFilter("opensessioninview",
            OpenEntityManagerInViewFilter.class);
    openSessionInViewFilter.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), false,
            "/*");
    
    aServletContext.addListener(HttpSessionEventPublisher.class);
}
 
Example 3
Source Project: activiti6-boot2   Source File: ActivitiUIApplication.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public FilterRegistrationBean openEntityManagerInViewFilter() {
    FilterRegistrationBean<OpenEntityManagerInViewFilter> filterRegistrationBean
            = new FilterRegistrationBean<>(new OpenEntityManagerInViewFilter());
    filterRegistrationBean.addUrlPatterns("/*");
    filterRegistrationBean.setName("openEntityManagerInViewFilter");
    filterRegistrationBean.setOrder(-200); // 必须在安全过滤器(-100)之前执行
    filterRegistrationBean.setDispatcherTypes(EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD));

    return filterRegistrationBean;
}
 
Example 4
Source Project: joinfaces   Source File: JpaWebAutoConfigurationTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testInterceptorReplacedByFilter() {
	this.webApplicationContextRunner.run(context -> {
		assertThat(context).doesNotHaveBean(OpenEntityManagerInViewInterceptor.class);
		assertThat(context).hasSingleBean(OpenEntityManagerInViewFilter.class);
	});
}
 
Example 5
Source Project: joinfaces   Source File: JpaWebAutoConfigurationTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testDisabledByProperty() {
	this.webApplicationContextRunner
			.withPropertyValues("spring.jpa.open-in-view=false")
			.run(context -> {
		assertThat(context).doesNotHaveBean(OpenEntityManagerInViewInterceptor.class);
		assertThat(context).doesNotHaveBean(OpenEntityManagerInViewFilter.class);
	});
}
 
Example 6
Source Project: joinfaces   Source File: JpaWebAutoConfigurationTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testDisabledByMissingEntityManagerClass() {
	this.webApplicationContextRunner
			.withClassLoader(new FilteredClassLoader(EntityManager.class))
			.run(context -> {
		assertThat(context).doesNotHaveBean(OpenEntityManagerInViewInterceptor.class);
		assertThat(context).doesNotHaveBean(OpenEntityManagerInViewFilter.class);
	});
}
 
Example 7
Source Project: we-cmdb   Source File: Application.java    License: Apache License 2.0 4 votes vote down vote up
@Override
protected Filter[] getServletFilters() {
    return new Filter[] { new OpenEntityManagerInViewFilter() };
}
 
Example 8
Source Project: we-cmdb   Source File: Application.java    License: Apache License 2.0 4 votes vote down vote up
@Override
protected Filter[] getServletFilters() {
    return new Filter[] { new OpenEntityManagerInViewFilter() };
}
 
Example 9
Source Project: joinfaces   Source File: JpaWebAutoConfiguration.java    License: Apache License 2.0 4 votes vote down vote up
@Bean
@ConditionalOnMissingBean({OpenEntityManagerInViewInterceptor.class, OpenEntityManagerInViewFilter.class})
@ConditionalOnMissingFilterBean(OpenEntityManagerInViewFilter.class)
public OpenEntityManagerInViewFilter openEntityManagerInViewFilter() {
	return new OpenEntityManagerInViewFilter();
}
 
Example 10
Source Project: cosmo   Source File: SecurityFilterConfig.java    License: Apache License 2.0 4 votes vote down vote up
@Bean
public FilterRegistrationBean<?> openEntityManagerInViewFilter() {
    FilterRegistrationBean<?> filterBean = new FilterRegistrationBean<>(new OpenEntityManagerInViewFilter());
    filterBean.addUrlPatterns(PATH_DAV);
    return filterBean;
}
 
Example 11
/**
 * Spring
 * 提供了FilterRegistrationBean类,此类提供setOrder方法,可以为filter设置排序值,让spring在注册web
 * filter之前排序后再依次注册。
 * 
 * @time 2018年4月10日 下午4:58:19.
 * 
 * @version V1.0
 * @return FilterRegistrationBean
 */
@Bean
public FilterRegistrationBean registFilter() {
	FilterRegistrationBean registration = new FilterRegistrationBean();
	registration.setFilter(new OpenEntityManagerInViewFilter());
	registration.addUrlPatterns("/*");
	registration.setOrder(1);
	return registration;
}