From df4e099458028a2e6e01f316520dc8a0f62bed48 Mon Sep 17 00:00:00 2001 From: Oliver Drotbohm Date: Thu, 28 Feb 2019 15:56:08 +0100 Subject: [PATCH] #838 - Improved registration of BeanPostProcessor implementations. The BeanPostProcessor implementations in (WebMVC|WebFlux)HateoasConfiguration are now declared as static methods and their dependencies use ObjectProvider wrapper types to prevent the need to prematurely initialize the entire configuration class which triggered the creation of a lot of downstream dependencies which were then reported as ineligible for post processing themselves. --- .../hateoas/config/WebFluxHateoasConfiguration.java | 7 ++++--- .../hateoas/config/WebMvcHateoasConfiguration.java | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/springframework/hateoas/config/WebFluxHateoasConfiguration.java b/src/main/java/org/springframework/hateoas/config/WebFluxHateoasConfiguration.java index 29638b40..55bf5910 100644 --- a/src/main/java/org/springframework/hateoas/config/WebFluxHateoasConfiguration.java +++ b/src/main/java/org/springframework/hateoas/config/WebFluxHateoasConfiguration.java @@ -54,7 +54,8 @@ class WebFluxHateoasConfiguration { } @Bean - HypermediaWebClientBeanPostProcessor webClientBeanPostProcessor(WebClientConfigurer configurer) { + static HypermediaWebClientBeanPostProcessor webClientBeanPostProcessor( + ObjectProvider configurer) { return new HypermediaWebClientBeanPostProcessor(configurer); } @@ -85,7 +86,7 @@ class WebFluxHateoasConfiguration { @RequiredArgsConstructor static class HypermediaWebClientBeanPostProcessor implements BeanPostProcessor { - private final WebClientConfigurer configurer; + private final ObjectProvider configurer; /* * (non-Javadoc) @@ -95,7 +96,7 @@ class WebFluxHateoasConfiguration { public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { if (bean instanceof WebClient) { - return this.configurer.registerHypermediaTypes((WebClient) bean); + return this.configurer.getObject().registerHypermediaTypes((WebClient) bean); } return bean; diff --git a/src/main/java/org/springframework/hateoas/config/WebMvcHateoasConfiguration.java b/src/main/java/org/springframework/hateoas/config/WebMvcHateoasConfiguration.java index ba12b9f2..3bdc985b 100644 --- a/src/main/java/org/springframework/hateoas/config/WebMvcHateoasConfiguration.java +++ b/src/main/java/org/springframework/hateoas/config/WebMvcHateoasConfiguration.java @@ -52,7 +52,8 @@ class WebMvcHateoasConfiguration { } @Bean - HypermediaRestTemplateBeanPostProcessor restTemplateBeanPostProcessor(HypermediaWebMvcConfigurer configurer) { + static HypermediaRestTemplateBeanPostProcessor restTemplateBeanPostProcessor( + ObjectProvider configurer) { return new HypermediaRestTemplateBeanPostProcessor(configurer); } @@ -100,7 +101,7 @@ class WebMvcHateoasConfiguration { @RequiredArgsConstructor static class HypermediaRestTemplateBeanPostProcessor implements BeanPostProcessor { - private final HypermediaWebMvcConfigurer configurer; + private final ObjectProvider configurer; /* * (non-Javadoc) @@ -113,7 +114,7 @@ class WebMvcHateoasConfiguration { return bean; } - configurer.extendMessageConverters(((RestTemplate) bean).getMessageConverters()); + configurer.getObject().extendMessageConverters(((RestTemplate) bean).getMessageConverters()); return bean; }