From d14140da69a98e11a11f241718bb0df2acb8afbc Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Sat, 6 Jun 2020 13:21:46 +0200 Subject: [PATCH] Polishing --- .../ReflectiveAspectJAdvisorFactory.java | 5 ++-- .../AspectJPrecedenceComparator.java | 12 +++------ .../DelegatingWebFluxConfiguration.java | 5 +++- .../config/WebFluxConfigurationSupport.java | 25 +++++++++++-------- 4 files changed, 24 insertions(+), 23 deletions(-) diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/ReflectiveAspectJAdvisorFactory.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/ReflectiveAspectJAdvisorFactory.java index 2f3896e90c..db6898f310 100644 --- a/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/ReflectiveAspectJAdvisorFactory.java +++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/ReflectiveAspectJAdvisorFactory.java @@ -76,9 +76,8 @@ public class ReflectiveAspectJAdvisorFactory extends AbstractAspectJAdvisorFacto new InstanceComparator<>( Around.class, Before.class, After.class, AfterReturning.class, AfterThrowing.class), (Converter) method -> { - AspectJAnnotation annotation = - AbstractAspectJAdvisorFactory.findAspectJAnnotationOnMethod(method); - return (annotation != null ? annotation.getAnnotation() : null); + AspectJAnnotation ann = AbstractAspectJAdvisorFactory.findAspectJAnnotationOnMethod(method); + return (ann != null ? ann.getAnnotation() : null); }); Comparator methodNameComparator = new ConvertingComparator<>(Method::getName); METHOD_COMPARATOR = adviceKindComparator.thenComparing(methodNameComparator); diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/autoproxy/AspectJPrecedenceComparator.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/autoproxy/AspectJPrecedenceComparator.java index 64066f7c04..d013cda2c9 100644 --- a/spring-aop/src/main/java/org/springframework/aop/aspectj/autoproxy/AspectJPrecedenceComparator.java +++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/autoproxy/AspectJPrecedenceComparator.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2020 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. @@ -138,14 +138,8 @@ class AspectJPrecedenceComparator implements Comparator { } private int getAspectDeclarationOrder(Advisor anAdvisor) { - AspectJPrecedenceInformation precedenceInfo = - AspectJAopUtils.getAspectJPrecedenceInformationFor(anAdvisor); - if (precedenceInfo != null) { - return precedenceInfo.getDeclarationOrder(); - } - else { - return 0; - } + AspectJPrecedenceInformation precedenceInfo = AspectJAopUtils.getAspectJPrecedenceInformationFor(anAdvisor); + return (precedenceInfo != null ? precedenceInfo.getDeclarationOrder() : 0); } } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/config/DelegatingWebFluxConfiguration.java b/spring-webflux/src/main/java/org/springframework/web/reactive/config/DelegatingWebFluxConfiguration.java index 1374cc4f05..9f4e147359 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/config/DelegatingWebFluxConfiguration.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/config/DelegatingWebFluxConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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. @@ -42,6 +42,7 @@ public class DelegatingWebFluxConfiguration extends WebFluxConfigurationSupport private final WebFluxConfigurerComposite configurers = new WebFluxConfigurerComposite(); + @Autowired(required = false) public void setConfigurers(List configurers) { if (!CollectionUtils.isEmpty(configurers)) { @@ -49,6 +50,7 @@ public class DelegatingWebFluxConfiguration extends WebFluxConfigurationSupport } } + @Override protected void configureContentTypeResolver(RequestedContentTypeResolverBuilder builder) { this.configurers.configureContentTypeResolver(builder); @@ -100,4 +102,5 @@ public class DelegatingWebFluxConfiguration extends WebFluxConfigurationSupport protected void configureViewResolvers(ViewResolverRegistry registry) { this.configurers.configureViewResolvers(registry); } + } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/config/WebFluxConfigurationSupport.java b/spring-webflux/src/main/java/org/springframework/web/reactive/config/WebFluxConfigurationSupport.java index f2f40e8ea5..02283d1eb1 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/config/WebFluxConfigurationSupport.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/config/WebFluxConfigurationSupport.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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. @@ -93,10 +93,6 @@ public class WebFluxConfigurationSupport implements ApplicationContextAware { @Nullable private ApplicationContext applicationContext; - @Nullable - public final ApplicationContext getApplicationContext() { - return this.applicationContext; - } @Override public void setApplicationContext(@Nullable ApplicationContext applicationContext) { @@ -108,6 +104,12 @@ public class WebFluxConfigurationSupport implements ApplicationContextAware { } } + @Nullable + public final ApplicationContext getApplicationContext() { + return this.applicationContext; + } + + @Bean public DispatcherHandler webHandler() { return new DispatcherHandler(); @@ -122,6 +124,7 @@ public class WebFluxConfigurationSupport implements ApplicationContextAware { @Bean public RequestMappingHandlerMapping requestMappingHandlerMapping( @Qualifier("webFluxContentTypeResolver") RequestedContentTypeResolver contentTypeResolver) { + RequestMappingHandlerMapping mapping = createRequestMappingHandlerMapping(); mapping.setOrder(0); mapping.setContentTypeResolver(contentTypeResolver); @@ -205,7 +208,7 @@ public class WebFluxConfigurationSupport implements ApplicationContextAware { @Bean public RouterFunctionMapping routerFunctionMapping(ServerCodecConfigurer serverCodecConfigurer) { RouterFunctionMapping mapping = createRouterFunctionMapping(); - mapping.setOrder(-1); // go before RequestMappingHandlerMapping + mapping.setOrder(-1); // go before RequestMappingHandlerMapping mapping.setMessageReaders(serverCodecConfigurer.getReaders()); mapping.setCorsConfigurations(getCorsConfigurations()); @@ -330,8 +333,8 @@ public class WebFluxConfigurationSupport implements ApplicationContextAware { * initializing all {@link WebDataBinder} instances. */ protected ConfigurableWebBindingInitializer getConfigurableWebBindingInitializer( - FormattingConversionService webFluxConversionService, - Validator webFluxValidator) { + FormattingConversionService webFluxConversionService, Validator webFluxValidator) { + ConfigurableWebBindingInitializer initializer = new ConfigurableWebBindingInitializer(); initializer.setConversionService(webFluxConversionService); initializer.setValidator(webFluxValidator); @@ -430,6 +433,7 @@ public class WebFluxConfigurationSupport implements ApplicationContextAware { @Qualifier("webFluxAdapterRegistry") ReactiveAdapterRegistry reactiveAdapterRegistry, ServerCodecConfigurer serverCodecConfigurer, @Qualifier("webFluxContentTypeResolver") RequestedContentTypeResolver contentTypeResolver) { + return new ResponseEntityResultHandler(serverCodecConfigurer.getWriters(), contentTypeResolver, reactiveAdapterRegistry); } @@ -439,6 +443,7 @@ public class WebFluxConfigurationSupport implements ApplicationContextAware { @Qualifier("webFluxAdapterRegistry") ReactiveAdapterRegistry reactiveAdapterRegistry, ServerCodecConfigurer serverCodecConfigurer, @Qualifier("webFluxContentTypeResolver") RequestedContentTypeResolver contentTypeResolver) { + return new ResponseBodyResultHandler(serverCodecConfigurer.getWriters(), contentTypeResolver, reactiveAdapterRegistry); } @@ -447,6 +452,7 @@ public class WebFluxConfigurationSupport implements ApplicationContextAware { public ViewResolutionResultHandler viewResolutionResultHandler( @Qualifier("webFluxAdapterRegistry") ReactiveAdapterRegistry reactiveAdapterRegistry, @Qualifier("webFluxContentTypeResolver") RequestedContentTypeResolver contentTypeResolver) { + ViewResolverRegistry registry = getViewResolverRegistry(); List resolvers = registry.getViewResolvers(); ViewResolutionResultHandler handler = new ViewResolutionResultHandler( @@ -457,8 +463,7 @@ public class WebFluxConfigurationSupport implements ApplicationContextAware { } @Bean - public ServerResponseResultHandler serverResponseResultHandler( - ServerCodecConfigurer serverCodecConfigurer) { + public ServerResponseResultHandler serverResponseResultHandler(ServerCodecConfigurer serverCodecConfigurer) { List resolvers = getViewResolverRegistry().getViewResolvers(); ServerResponseResultHandler handler = new ServerResponseResultHandler(); handler.setMessageWriters(serverCodecConfigurer.getWriters());