Switch to SmartInitializingSingleton to avoid early instantiation

Use of BeanProcessor to catch a bean before it is used is a bit
agricultural these days. SmartInitializingSingleton is better and
frees application logs from one more annoying INFO log on an
early instantiation

2018-01-04 14:17:05.930  INFO 23472 --- [       Thread-0] trationDelegate$BeanPostProcessorChecker :
  Bean 'org.springframework.cloud.function.web.flux.ReactorAutoConfiguration' of type
  [org.springframework.cloud.function.web.flux.ReactorAutoConfiguration$$EnhancerBySpringCGLIB$$8d4844e]
  is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
This commit is contained in:
Dave Syer
2018-01-04 14:27:32 +00:00
parent 9c1a9bff4e
commit 7b46f925d7

View File

@@ -21,9 +21,8 @@ import java.util.List;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.beans.BeansException; import org.springframework.beans.factory.SmartInitializingSingleton;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
@@ -81,17 +80,16 @@ public class ReactorAutoConfiguration {
} }
@Bean @Bean
public BeanPostProcessor fluxRequestMappingHandlerAdapterProcessor() { public SmartInitializingSingleton fluxRequestMappingHandlerAdapterProcessor(
return new BeanPostProcessor() { RequestMappingHandlerAdapter adapter,
FluxHandlerMethodArgumentResolver resolver) {
return new SmartInitializingSingleton() {
@Override @Override
public Object postProcessAfterInitialization(Object bean, String beanName) public void afterSingletonsInstantiated() {
throws BeansException {
if (bean instanceof RequestMappingHandlerAdapter) {
RequestMappingHandlerAdapter adapter = (RequestMappingHandlerAdapter) bean;
List<HandlerMethodArgumentResolver> resolvers = new ArrayList<>( List<HandlerMethodArgumentResolver> resolvers = new ArrayList<>(
adapter.getArgumentResolvers()); adapter.getArgumentResolvers());
resolvers.add(0, resolvers.add(0, resolver);
context.getBean(FluxHandlerMethodArgumentResolver.class));
adapter.setArgumentResolvers(resolvers); adapter.setArgumentResolvers(resolvers);
if (!ClassUtils.isPresent("org.springframework.core.ReactiveAdapter", if (!ClassUtils.isPresent("org.springframework.core.ReactiveAdapter",
null)) { null)) {
@@ -101,14 +99,7 @@ public class ReactorAutoConfiguration {
adapter.setReturnValueHandlers(handlers); adapter.setReturnValueHandlers(handlers);
} }
} }
return bean;
}
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName)
throws BeansException {
return bean;
}
}; };
} }
} }