mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-09-03 04:26:12 +08:00
Do not auto-configure OEMIV filter when user defines registration bean
See gh-15889
This commit is contained in:
parent
88fd84aa56
commit
4f86233ca7
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -39,6 +39,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplicat
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type;
|
||||
import org.springframework.boot.autoconfigure.domain.EntityScanPackages;
|
||||
import org.springframework.boot.autoconfigure.transaction.TransactionManagerCustomizers;
|
||||
import org.springframework.boot.autoconfigure.web.servlet.ConditionalOnMissingFilterBean;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@ -211,6 +212,7 @@ public abstract class JpaBaseConfiguration implements BeanFactoryAware {
|
||||
@ConditionalOnClass(WebMvcConfigurer.class)
|
||||
@ConditionalOnMissingBean({ OpenEntityManagerInViewInterceptor.class,
|
||||
OpenEntityManagerInViewFilter.class })
|
||||
@ConditionalOnMissingFilterBean(OpenEntityManagerInViewFilter.class)
|
||||
@ConditionalOnProperty(prefix = "spring.jpa", name = "open-in-view", havingValue = "true", matchIfMissing = true)
|
||||
protected static class JpaWebConfiguration {
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -38,6 +38,7 @@ import org.springframework.boot.test.context.assertj.AssertableApplicationContex
|
||||
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
||||
import org.springframework.boot.test.context.runner.ContextConsumer;
|
||||
import org.springframework.boot.test.context.runner.WebApplicationContextRunner;
|
||||
import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
@ -159,6 +160,32 @@ public abstract class AbstractJpaAutoConfigurationTests {
|
||||
.doesNotHaveBean(OpenEntityManagerInViewInterceptor.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void openEntityManagerInViewInterceptorIsNotRegisteredWhenFilterRegistrationPresent() {
|
||||
new WebApplicationContextRunner()
|
||||
.withPropertyValues("spring.datasource.generate-unique-name=true")
|
||||
.withUserConfiguration(TestFilterRegistrationConfiguration.class)
|
||||
.withConfiguration(AutoConfigurations.of(
|
||||
DataSourceAutoConfiguration.class,
|
||||
TransactionAutoConfiguration.class, this.autoConfiguredClass))
|
||||
.run((context) -> assertThat(context)
|
||||
.doesNotHaveBean(OpenEntityManagerInViewInterceptor.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void openEntityManagerInViewInterceptorAutoConfigurationBacksOffWhenManuallyRegistered() {
|
||||
new WebApplicationContextRunner()
|
||||
.withPropertyValues("spring.datasource.generate-unique-name=true")
|
||||
.withUserConfiguration(TestInterceptorManualConfiguration.class)
|
||||
.withConfiguration(AutoConfigurations.of(
|
||||
DataSourceAutoConfiguration.class,
|
||||
TransactionAutoConfiguration.class, this.autoConfiguredClass))
|
||||
.run((context) -> assertThat(context)
|
||||
.getBean(OpenEntityManagerInViewInterceptor.class)
|
||||
.isExactlyInstanceOf(
|
||||
TestInterceptorManualConfiguration.ManualOpenEntityManagerInViewInterceptor.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void openEntityManagerInViewInterceptorISNotRegisteredWhenExplicitlyOff() {
|
||||
new WebApplicationContextRunner()
|
||||
@ -298,6 +325,33 @@ public abstract class AbstractJpaAutoConfigurationTests {
|
||||
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@TestAutoConfigurationPackage(City.class)
|
||||
protected static class TestFilterRegistrationConfiguration {
|
||||
|
||||
@Bean
|
||||
public FilterRegistrationBean<OpenEntityManagerInViewFilter> OpenEntityManagerInViewFilterFilterRegistrationBean() {
|
||||
return new FilterRegistrationBean<>();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@TestAutoConfigurationPackage(City.class)
|
||||
protected static class TestInterceptorManualConfiguration {
|
||||
|
||||
@Bean
|
||||
public OpenEntityManagerInViewInterceptor openEntityManagerInViewInterceptor() {
|
||||
return new ManualOpenEntityManagerInViewInterceptor();
|
||||
}
|
||||
|
||||
protected static class ManualOpenEntityManagerInViewInterceptor
|
||||
extends OpenEntityManagerInViewInterceptor {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Configuration
|
||||
protected static class TestConfigurationWithLocalContainerEntityManagerFactoryBean
|
||||
extends TestConfiguration {
|
||||
|
Loading…
Reference in New Issue
Block a user