Introduce WebMvcConfigurerAdapter with default methods and interceptor registration#225
Merged
Merged
Conversation
…s#224 Add a new WebMvcConfigurerAdapter interface that provides Java 8 default no-op implementations for all WebMvcConfigurer methods, replacing the older WebMvcConfigurerAdapter class pattern and avoiding single-inheritance issues. Also add WebMvcConfigurerAdapterTest to exercise each default method and assert that getValidator() and getMessageCodesResolver() return null.
Remove the WebMvcConfigurerAdapter import and update the class declaration from extending WebMvcConfigurerAdapter to implementing it (class now declares 'implements WebMvcConfigurerAdapter, EnvironmentAware'). This adjusts the class' inheritance/implementation to reflect the updated usage in the codebase.
Make InterceptingHandlerMethodProcessor register itself as a Spring MVC interceptor by implementing WebMvcConfigurerAdapter and adding this to the InterceptorRegistry (addInterceptors). Also update LazyCompositeHandlerInterceptor to ignore beans of type InterceptingHandlerMethodProcessor when collecting interceptors to avoid self-inclusion/double-registration. Imports were added accordingly.
Change access modifier of parseExpressions from protected to public in WebRequestHeaderExpression and WebRequestParamExpression. This exposes the static parsing utilities so callers outside the package can construct lists of header/parameter expressions; no other logic was modified.
Delete the placeholder WebEndpointMappingExpressionVisitor implementation (microsphere-spring-web/src/main/java/io/microsphere/spring/web/metadata/WebEndpointMappingExpressionVisitor.java). The class contained only empty visitor methods and an unused StringBuilder, so it was removed to clean up dead/unused code.
Introduce expression-building APIs for WebEndpointMapping: add toExpression() and several static helpers to render methods, patterns, params, headers, consumes and produces as a readable boolean-style expression string. Add normalization functions (normalizeParam/normalizeHeader/normalizeConsume/normalizeProduce), parseNameAndValue, and utility toExpression overloads. Restore builder factory methods and various builder utilities (pair, newSet, toStrings, assertBuilders) and update imports to support StringJoiner, split, EMPTY_STRING, EQUAL, and parentheses symbols. Javadocs/examples included to clarify expected expression formats.
Add testToExpression() to WebEndpointMappingTest to verify mapping.toExpression() output for various combinations (methods, patterns, params, headers, consumes/produces, negation and multi-value cases) and edge cases for the toExpression utility. Also introduce a builder() test helper and update static imports (assertBuilders, pair, toExpression, toStrings and EMPTY_STRING) to reflect usage in the new tests.
Introduce an auto-registration framework for Spring beans loaded via Spring Factories: adds AutoRegistrationBean (marker/configuration interface), EnableAutoRegistrationBean annotation, and AutoRegistrationBeanRegistrar to register SPI-provided beans conditionally based on environment properties. Adds PropertyConstants for bean-related property names and defaults (microsphere.spring.beans.* and auto-registered flag), utilities for building BeanDefinitions with instance suppliers (BeanDefinitionBuilderUtils) and small enhancements to BeanCapableImportCandidate and ImportOptionalSelector to support placeholder-resolvable annotation attributes and access to the application context. Includes unit tests and test AutoRegistrationBean implementations, and registers test beans in test/resources/META-INF/spring.factories.
Implement ApplicationContextAware in BeanCapableImportCandidate: add a ConfigurableApplicationContext field, a final setApplicationContext(...) implementation, and return the stored applicationContext from getApplicationContext(). Introduce a NO_CLASS_TO_IMPORT constant. Remove a redundant setApplicationContext override from PropertySourceExtensionLoader and remove the logger field/import from AnnotatedPropertySourceLoader. Update tests to assert the new applicationContext handling and related invariants.
Introduce AnnotatedBeanCapableImportCandidate to centralize generic annotation handling for annotated Configuration import candidates and update AutoRegistrationBeanRegistrar to extend it. Refactor PropertySourceExtensionLoader to use ConfigurableApplicationContext (remove ApplicationContextAware and the context field), call getApplicationContext() where needed, and use the superclass generic resolver for type resolution. Also apply minor Javadoc/whitespace fixes in dependency resolver classes.
Switch several import-loader/selectors to extend the new AnnotatedBeanCapableImportCandidate<T> generic base instead of the non-annotated BeanCapableImportCandidate. This removes manual annotation type resolution and ResolvableType usage, and centralizes annotation attribute retrieval via getAnnotationAttributes(metadata). Updated: AnnotatedPropertySourceLoader, DefaultPropertiesPropertySourceLoader, DefaultPropertiesPropertySourcesLoader, ImportOptionalSelector. Also tightened a log message in AnnotatedPropertySourceLoader and added a small javadoc note in BeanCapableImportCandidate.
Bump README branch table entries: set latest versions to 0.2.15 and 0.1.15, and expand 0.2.x compatibility to include Spring Framework 7.0.x. This replaces the prior -SNAPSHOT placeholders to reflect released versions.
Extract and relocate shared web test utilities and test configs into a new microsphere-spring-test module (moved classes from webflux/webmvc test packages into io.microsphere.spring.test.*). Add WebTestUtils constants and a Mono getValue helper to support non-blocking threads. Update many tests/imports to reference the new packages, add new unit tests (WebTestUtilsTest, SimpleUrlHandlerMappingTestConfigTest, WebMvcTest), and adjust test behaviors (CompositeWebFilter usage, WebTestClient builder visibility, and delegation of testWebEndpoints). Also update microsphere-spring-test/pom.xml: reorganize dependencies to optional scope, add spring-webflux and jsonassert as optional deps, and add a spring-framework-4.3 compatibility profile.
Move the EnableWebMvcExtension import to group with other webmvc imports in HandlerMappingWebEndpointMappingResolverTest and InterceptingHandlerMethodProcessorTest. This is a non-functional change to tidy import ordering in test sources.
|
5eda26b
into
microsphere-projects:dev-1.x
16 of 27 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



This pull request introduces a new
WebMvcConfigurerAdapterinterface to replace the deprecated SpringWebMvcConfigurerAdapterclass, leveraging Java 8 default methods for backward compatibility and easier extension. It also updates existing components to use this new interface and adds a corresponding test class. Additionally, it improves how interceptors are registered and filtered within the framework.The most important changes are:
Introduction and Adoption of
WebMvcConfigurerAdapterWebMvcConfigurerAdapterinterface that provides default (empty) implementations for allWebMvcConfigurermethods, simplifying custom configuration and avoiding the limitations of single inheritance in Java.ConfigurableContentNegotiationManagerWebMvcConfigurerandInterceptingHandlerMethodProcessorto implement the newWebMvcConfigurerAdapterinterface instead of the old class, ensuring compatibility and maintainability. [1] [2]Interceptor Registration and Filtering
InterceptingHandlerMethodProcessorto automatically register itself as an interceptor via the newaddInterceptorsmethod, streamlining its integration into the Spring MVC interceptor chain.LazyCompositeHandlerInterceptorto skip both itself and any instances ofInterceptingHandlerMethodProcessor, preventing redundant or recursive registrations.Testing and Validation
WebMvcConfigurerAdapterTestto verify that all default methods in the new interface are correctly implemented and behave as expected.Dependency Management
WebMvcConfigurerAdapterinterface where appropriate. [1] [2] [3] [4]