Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose config field in RequestMappingHandlerMapping to subclasses #27871

Closed
wants to merge 1 commit into from
Closed

Expose config field in RequestMappingHandlerMapping to subclasses #27871

wants to merge 1 commit into from

Conversation

shenjianeng
Copy link

in my project , I hava a PlatformRequestMappingHandlerMapping。

public class PlatformRequestMappingHandlerMapping extends RequestMappingHandlerMapping {

    @Override
    protected RequestMappingInfo getMappingForMethod(Method method, Class<?> handlerType) {
        RequestMappingInfo requestMappingInfo = super.getMappingForMethod(method, handlerType);
        if (requestMappingInfo != null)
            return requestMappingInfo;
        return createCustomRequestMappingInfo(method);
    }

    private RequestMappingInfo createCustomRequestMappingInfo(AnnotatedElement element) {
        PlatformRestMapping mapping = AnnotatedElementUtils.findMergedAnnotation(element, PlatformRestMapping.class);
        // ....
        return RequestMappingInfo.paths(URI_PREFIX_OF_API + mapping.value())
                .methods(methods)
                .options(getConfig()) // need use super.config
                .build();
    }

    // bad impl
    private RequestMappingInfo.BuilderConfiguration getConfig() {
        try {
            Object config = FieldUtils.readField(this, "config", true);
            return (RequestMappingInfo.BuilderConfiguration) config;
        } catch (IllegalAccessException e) {
            throw new RuntimeException("config");
        }

    }
}

@sbrannen sbrannen added in: web Issues in web modules (web, webmvc, webflux, websocket) status: duplicate A duplicate of another issue labels Jan 3, 2022
@sbrannen
Copy link
Member

sbrannen commented Jan 3, 2022

A new public RequestMappingInfo.BuilderConfiguration getBuilderConfiguration() method was introduced in RequestMappingHandlerMapping in 5.3.14.

I am therefore closing this as a duplicate of #27723.

@sbrannen sbrannen closed this Jan 3, 2022
@spring-projects spring-projects deleted a comment from shenjianeng Jan 3, 2022
@sbrannen sbrannen changed the title expose config Expose config field in RequestMappingHandlerMapping to subclasses Jan 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: duplicate A duplicate of another issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants