Skip to content

Introduce WebMvcConfigurerAdapter with default methods and interceptor registration#225

Merged
mercyblitz merged 14 commits into
microsphere-projects:dev-1.xfrom
mercyblitz:dev-1.x
May 9, 2026
Merged

Introduce WebMvcConfigurerAdapter with default methods and interceptor registration#225
mercyblitz merged 14 commits into
microsphere-projects:dev-1.xfrom
mercyblitz:dev-1.x

Conversation

@mercyblitz
Copy link
Copy Markdown
Contributor

This pull request introduces a new WebMvcConfigurerAdapter interface to replace the deprecated Spring WebMvcConfigurerAdapter class, 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 WebMvcConfigurerAdapter

  • Added a new WebMvcConfigurerAdapter interface that provides default (empty) implementations for all WebMvcConfigurer methods, simplifying custom configuration and avoiding the limitations of single inheritance in Java.
  • Updated ConfigurableContentNegotiationManagerWebMvcConfigurer and InterceptingHandlerMethodProcessor to implement the new WebMvcConfigurerAdapter interface instead of the old class, ensuring compatibility and maintainability. [1] [2]

Interceptor Registration and Filtering

  • Enhanced InterceptingHandlerMethodProcessor to automatically register itself as an interceptor via the new addInterceptors method, streamlining its integration into the Spring MVC interceptor chain.
  • Improved interceptor filtering in LazyCompositeHandlerInterceptor to skip both itself and any instances of InterceptingHandlerMethodProcessor, preventing redundant or recursive registrations.

Testing and Validation

  • Added a dedicated test class WebMvcConfigurerAdapterTest to verify that all default methods in the new interface are correctly implemented and behave as expected.

Dependency Management

  • Updated imports throughout relevant classes to reference the new WebMvcConfigurerAdapter interface where appropriate. [1] [2] [3] [4]

mercyblitz added 3 commits May 7, 2026 21:20
…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.
@codecov
Copy link
Copy Markdown

codecov Bot commented May 7, 2026

Codecov Report

❌ Patch coverage is 95.85492% with 8 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...osphere/spring/test/webmvc/AbstractWebMvcTest.java 0.00% 6 Missing ⚠️
...re/spring/context/config/AutoRegistrationBean.java 85.71% 2 Missing ⚠️
Files with missing lines Coverage Δ Complexity Δ
...tory/AbstractInjectionPointDependencyResolver.java 85.24% <ø> (ø) 21.00 <0.00> (ø)
...g/beans/factory/DefaultBeanDependencyResolver.java 0.00% <ø> (ø) 0.00 <0.00> (ø)
...ns/factory/support/BeanDefinitionBuilderUtils.java 100.00% <100.00%> (ø) 4.00 <4.00> (?)
...text/annotation/AnnotatedPropertySourceLoader.java 92.00% <100.00%> (-2.12%) 8.00 <2.00> (-2.00)
...otation/DefaultPropertiesPropertySourceLoader.java 93.75% <100.00%> (-0.25%) 15.00 <2.00> (-1.00)
...tation/DefaultPropertiesPropertySourcesLoader.java 100.00% <100.00%> (ø) 4.00 <3.00> (ø)
...text/annotation/PropertySourceExtensionLoader.java 78.36% <100.00%> (-0.21%) 43.00 <7.00> (-1.00)
...icrosphere/spring/constants/PropertyConstants.java 100.00% <100.00%> (ø) 1.00 <1.00> (?)
...nnotation/AnnotatedBeanCapableImportCandidate.java 100.00% <100.00%> (ø) 5.00 <5.00> (?)
...text/annotation/AutoRegistrationBeanRegistrar.java 100.00% <100.00%> (ø) 13.00 <13.00> (?)
... and 17 more

... and 14 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

mercyblitz added 11 commits May 7, 2026 22:17
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.
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented May 9, 2026

@mercyblitz mercyblitz merged commit 5eda26b into microsphere-projects:dev-1.x May 9, 2026
16 of 27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant