spring-cloud / spring-cloud-openfeign

Support for using OpenFeign in Spring Cloud apps
Apache License 2.0
1.2k stars 779 forks source link

Improve RequestParam annotation parameter processor logic #991

Closed ruansheng8 closed 6 months ago

ruansheng8 commented 7 months ago

Description

If the logic in the processArgument method does not appear in a specific annotation class, I will be able to directly reuse the original logic to encapsulate custom annotations.

public class RpcHeaderParameterProcessor extends RequestHeaderParameterProcessor {

    private static final Class<RpcHeader> ANNOTATION = RpcHeader.class;

    @Override
    public Class<? extends Annotation> getAnnotationType() {
        return ANNOTATION;
    }

    @Override
    public boolean processArgument(AnnotatedParameterContext context, Annotation annotation, Method method) {
        // DO SOMETHING
        return super.processArgument(context, annotation, method);
    }

}

Similar Code

https://github.com/spring-cloud/spring-cloud-openfeign/blob/bd560f1fffee2beee6f1496f4522dceb340108fb/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/annotation/RequestHeaderParameterProcessor.java#L61

OlgaMaciaszek commented 6 months ago

Hello @ruansheng8 - that processor is specifically for the @RequestParam annotation. Just create your own AnnotatedParameterProcessor implementation and instantiate it as bean - it will be autowired.

ruansheng8 commented 6 months ago

Hello @ruansheng8 - that processor is specifically for the @RequestParam annotation. Just create your own AnnotatedParameterProcessor implementation and instantiate it as bean - it will be autowired.

You're right, thanks !