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:
@@ -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,34 +80,26 @@ public class ReactorAutoConfiguration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public BeanPostProcessor fluxRequestMappingHandlerAdapterProcessor() {
|
public SmartInitializingSingleton fluxRequestMappingHandlerAdapterProcessor(
|
||||||
return new BeanPostProcessor() {
|
RequestMappingHandlerAdapter adapter,
|
||||||
@Override
|
FluxHandlerMethodArgumentResolver resolver) {
|
||||||
public Object postProcessAfterInitialization(Object bean, String beanName)
|
return new SmartInitializingSingleton() {
|
||||||
throws BeansException {
|
|
||||||
if (bean instanceof RequestMappingHandlerAdapter) {
|
|
||||||
RequestMappingHandlerAdapter adapter = (RequestMappingHandlerAdapter) bean;
|
|
||||||
List<HandlerMethodArgumentResolver> resolvers = new ArrayList<>(
|
|
||||||
adapter.getArgumentResolvers());
|
|
||||||
resolvers.add(0,
|
|
||||||
context.getBean(FluxHandlerMethodArgumentResolver.class));
|
|
||||||
adapter.setArgumentResolvers(resolvers);
|
|
||||||
if (!ClassUtils.isPresent("org.springframework.core.ReactiveAdapter",
|
|
||||||
null)) {
|
|
||||||
List<HandlerMethodReturnValueHandler> handlers = new ArrayList<>(
|
|
||||||
adapter.getReturnValueHandlers());
|
|
||||||
handlers.add(0, context.getBean(FluxReturnValueHandler.class));
|
|
||||||
adapter.setReturnValueHandlers(handlers);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return bean;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object postProcessBeforeInitialization(Object bean, String beanName)
|
public void afterSingletonsInstantiated() {
|
||||||
throws BeansException {
|
List<HandlerMethodArgumentResolver> resolvers = new ArrayList<>(
|
||||||
return bean;
|
adapter.getArgumentResolvers());
|
||||||
|
resolvers.add(0, resolver);
|
||||||
|
adapter.setArgumentResolvers(resolvers);
|
||||||
|
if (!ClassUtils.isPresent("org.springframework.core.ReactiveAdapter",
|
||||||
|
null)) {
|
||||||
|
List<HandlerMethodReturnValueHandler> handlers = new ArrayList<>(
|
||||||
|
adapter.getReturnValueHandlers());
|
||||||
|
handlers.add(0, context.getBean(FluxReturnValueHandler.class));
|
||||||
|
adapter.setReturnValueHandlers(handlers);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user