version:1.4.5
I try to add a Custom AnnotatedParameterProcessor to solve the problem that feign use get method type to transfer Object param. Then i found that IllegalStateException: Method has too many Body parameters occurred at startup. This reason is SpringMvcContract construct
List<AnnotatedParameterProcessor> processors;
if (!annotatedParameterProcessors.isEmpty()) {
processors = new ArrayList<>(annotatedParameterProcessors);
}
else {
processors = getDefaultAnnotatedArgumentsProcessors();
}
this.annotatedArgumentProcessors = toAnnotatedArgumentProcessorMap(processors);
When Custom AnnotatedParameterProcessors exist,DefaultAnnotatedArgumentsProcessors is not obtained.
Generally speaking,for multiple objects that can exist in spring container,custom a object to spring container mean that add a custom object instead of replace default objects.
I think this is a bug? Otherwise,how to keep the default setting and add a my AnnotatedParameterProcessor In this condition?
Comment From: spencergibb
I don't know about annotation processors. It's not a feature of spring cloud Netflix. I'd try on stack overflow.
Comment From: liudaomanbu
This class in project.
org.springframework.cloud.netflix.feign.support.SpringMvcContract
org.springframework.cloud.netflix.feign.AnnotatedParameterProcessor
Comment From: spencergibb
Ok. Can you back up and describe what you are trying to accomplish regardless of annotation processors?
Comment From: liudaomanbu
I want to add a my annotation processor and keep the default annotation processors.
private List<AnnotatedParameterProcessor> getDefaultAnnotatedArgumentsProcessors() {
List<AnnotatedParameterProcessor> annotatedArgumentResolvers = new ArrayList<>();
annotatedArgumentResolvers.add(new PathVariableParameterProcessor());
annotatedArgumentResolvers.add(new RequestParamParameterProcessor());
annotatedArgumentResolvers.add(new RequestHeaderParameterProcessor());
return annotatedArgumentResolvers;
}
This is the default annotation processors now. So i want to add a my annotation processor such as a GetParamAnnotatedParameterProcessor.
@Configuration
public class AutoConfigure{
@Bean
public GetParamAnnotatedParameterProcessor getParamAnnotatedParameterProcessor(){
return new GetParamAnnotatedParameterProcessor();
}
}
I hope the annotation processor list should be PathVariableParameterProcessor,RequestParamParameterProcessor,RequestHeaderParameterProcessor and my GetParamAnnotatedParameterProcessor.
Actually the annotation processor list is only my GetParamAnnotatedParameterProcessor.
Comment From: spencergibb
Why do you want to add your annotation processor. What does it do, that the current ones do not?
Comment From: liudaomanbu
Why do you want to add your annotation processor. What does it do, that the current ones do not?
I try to add a Custom AnnotatedParameterProcessor to parse POJO param to url when the method type is Get. For example
@Data
public class Param{
String id;
String name;
}
@FeignClient("bhc-health-record-service")
public interface UserServiceFeignClient{
@RequestMapping(value ="/users",method = RequestMethod.GET)
User get(@GetParam Param param);
}
The url is "/users?id=xxx&name=xxx".
Comment From: brunneng
As a workaround you can define this 4 default parameter processors as beans in configuration, corresponding to your feign client:
@Bean
public AnnotatedParameterProcessor pathVariableParameterProcessor() {
return new PathVariableParameterProcessor();
}
@Bean
public AnnotatedParameterProcessor requestParamParameterProcessor() {
return new RequestParamParameterProcessor();
}
@Bean
public AnnotatedParameterProcessor requestHeaderParameterProcessor() {
return new RequestHeaderParameterProcessor();
}
@Bean
public AnnotatedParameterProcessor queryMapParameterProcessor() {
return new QueryMapParameterProcessor();
}