mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-08-29 03:06:45 +08:00
Merge branch '2.7.x'
Closes gh-31152
This commit is contained in:
commit
f9db6ad237
@ -40,6 +40,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
|||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.web.servlet.ConditionalOnMissingFilterBean;
|
||||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||||
import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
@ -79,7 +80,7 @@ public class WebMvcMetricsAutoConfiguration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnMissingBean
|
@ConditionalOnMissingFilterBean
|
||||||
public FilterRegistrationBean<WebMvcMetricsFilter> webMvcMetricsFilter(MeterRegistry registry,
|
public FilterRegistrationBean<WebMvcMetricsFilter> webMvcMetricsFilter(MeterRegistry registry,
|
||||||
WebMvcTagsProvider tagsProvider) {
|
WebMvcTagsProvider tagsProvider) {
|
||||||
ServerRequest request = this.properties.getWeb().getServer().getRequest();
|
ServerRequest request = this.properties.getWeb().getServer().getRequest();
|
||||||
|
@ -121,14 +121,34 @@ class WebMvcMetricsAutoConfigurationTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void filterRegistrationBacksOff() {
|
void filterRegistrationBacksOffWithAnotherWebMvcMetricsFilterRegistration() {
|
||||||
this.contextRunner.withUserConfiguration(TestWebMvcMetricsFilterConfiguration.class).run((context) -> {
|
this.contextRunner.withUserConfiguration(TestWebMvcMetricsFilterRegistrationConfiguration.class)
|
||||||
|
.run((context) -> {
|
||||||
assertThat(context).hasSingleBean(FilterRegistrationBean.class);
|
assertThat(context).hasSingleBean(FilterRegistrationBean.class);
|
||||||
assertThat(context.getBean(FilterRegistrationBean.class))
|
assertThat(context.getBean(FilterRegistrationBean.class))
|
||||||
.isSameAs(context.getBean("testWebMvcMetricsFilter"));
|
.isSameAs(context.getBean("testWebMvcMetricsFilter"));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void filterRegistrationBacksOffWithAnotherWebMvcMetricsFilter() {
|
||||||
|
this.contextRunner.withUserConfiguration(TestWebMvcMetricsFilterConfiguration.class)
|
||||||
|
.run((context) -> assertThat(context).doesNotHaveBean(FilterRegistrationBean.class)
|
||||||
|
.hasSingleBean(WebMvcMetricsFilter.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void filterRegistrationDoesNotBackOffWithOtherFilterRegistration() {
|
||||||
|
this.contextRunner.withUserConfiguration(TestFilterRegistrationConfiguration.class)
|
||||||
|
.run((context) -> assertThat(context).hasBean("testFilter").hasBean("webMvcMetricsFilter"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void filterRegistrationDoesNotBackOffWithOtherFilter() {
|
||||||
|
this.contextRunner.withUserConfiguration(TestFilterConfiguration.class)
|
||||||
|
.run((context) -> assertThat(context).hasBean("testFilter").hasBean("webMvcMetricsFilter"));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void afterMaxUrisReachedFurtherUrisAreDenied(CapturedOutput output) {
|
void afterMaxUrisReachedFurtherUrisAreDenied(CapturedOutput output) {
|
||||||
this.contextRunner.withUserConfiguration(TestController.class)
|
this.contextRunner.withUserConfiguration(TestController.class)
|
||||||
@ -257,7 +277,7 @@ class WebMvcMetricsAutoConfigurationTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Configuration(proxyBeanMethods = false)
|
@Configuration(proxyBeanMethods = false)
|
||||||
static class TestWebMvcMetricsFilterConfiguration {
|
static class TestWebMvcMetricsFilterRegistrationConfiguration {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@ -267,4 +287,35 @@ class WebMvcMetricsAutoConfigurationTests {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Configuration(proxyBeanMethods = false)
|
||||||
|
static class TestWebMvcMetricsFilterConfiguration {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
WebMvcMetricsFilter testWebMvcMetricsFilter() {
|
||||||
|
return new WebMvcMetricsFilter(null, null, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Configuration(proxyBeanMethods = false)
|
||||||
|
static class TestFilterRegistrationConfiguration {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
FilterRegistrationBean<Filter> testFilter() {
|
||||||
|
return mock(FilterRegistrationBean.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Configuration(proxyBeanMethods = false)
|
||||||
|
static class TestFilterConfiguration {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
Filter testFilter() {
|
||||||
|
return mock(Filter.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user