@Override public void addInterceptors(final InterceptorRegistry registry) { for (final EntityManagerFactory entityManagerFactory : entityManagerFactories) { final OpenEntityManagerInViewInterceptor openEntityManagerInViewInterceptor = new OpenEntityManagerInViewInterceptor(); openEntityManagerInViewInterceptor.setEntityManagerFactory(entityManagerFactory); registry.addWebRequestInterceptor(openEntityManagerInViewInterceptor); } super.addInterceptors(registry); }
@Test public void testOpenEntityManagerInViewInterceptorCreated() throws Exception { AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); context.register(TestConfiguration.class, EmbeddedDataSourceConfiguration.class, PropertyPlaceholderAutoConfiguration.class, getAutoConfigureClass()); context.refresh(); assertThat(context.getBean(OpenEntityManagerInViewInterceptor.class)).isNotNull(); context.close(); }
@Test public void testOpenEntityManagerInViewInterceptorCreated() throws Exception { AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); context.register(TestConfiguration.class, EmbeddedDataSourceConfiguration.class, PropertyPlaceholderAutoConfiguration.class, getAutoConfigureClass()); context.refresh(); assertNotNull(context.getBean(OpenEntityManagerInViewInterceptor.class)); context.close(); }
@Test(expected = NoSuchBeanDefinitionException.class) public void testInterceptorDisabled() { this.applicationContext.getBean(OpenEntityManagerInViewInterceptor.class); }
@Bean public OpenEntityManagerInViewInterceptor openEntityManagerInViewInterceptor() { return new OpenEntityManagerInViewInterceptor(); }
private String[] getInterceptorBeans(ApplicationContext context) { return context.getBeanNamesForType(OpenEntityManagerInViewInterceptor.class); }
@Bean public OpenEntityManagerInViewInterceptor openEntityManagerInViewInterceptor() { OpenEntityManagerInViewInterceptor oemiv = new OpenEntityManagerInViewInterceptor(); oemiv.setEntityManagerFactory(entityManagerFactory); return oemiv; }