原因是SpringMVC在扫描restful接口的时候扫描了带有RequestMapping
注解的类,其实我觉得大可不必。。。
解决方法就是修改扫描规则,如果类上已经有了FeignClient注解,就忽略掉即可。
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.web.servlet.WebMvcRegistrations;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.AnnotatedElementUtils;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
/**
* @author kdyzm
* @date 2022/11/14
*/
@Configuration
@ConditionalOnClass({FeignClient.class})
public class FeignConfiguration {
@Bean
public WebMvcRegistrations feignWebRegistrations() {
return new WebMvcRegistrations() {
@Override
public RequestMappingHandlerMapping getRequestMappingHandlerMapping() {
return new FeignRequestMappingHandlerMapping();
}
};
}
private static class FeignRequestMappingHandlerMapping extends RequestMappingHandlerMapping {
@Override
protected boolean isHandler(Class<?> beanType) {
if (AnnotatedElementUtils.hasAnnotation(beanType, FeignClient.class)) {
return false;
}
return super.isHandler(beanType);
}
}
}
注意:本文归作者所有,未经作者允许,不得转载