解决controller和feign,RequestMapping重名问题

package com.jeesun.gc.jeesungoods.config;

import org.springframework.boot.autoconfigure.web.servlet.WebMvcRegistrations;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.AnnotatedElementUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;

 
@Configuration
public class WebMvcRegistrationAdpater implements WebMvcRegistrations {

    @Override
    public RequestMappingHandlerMapping getRequestMappingHandlerMapping() {
        return new MyRequestMappingHandlerMapping();
    }

    public class MyRequestMappingHandlerMapping extends RequestMappingHandlerMapping {


        @Override
        protected boolean isHandler(Class<?> beanType) {

            // 原来逻辑:
            /*
            return (AnnotatedElementUtils.hasAnnotation(beanType, Controller.class) ||
                    AnnotatedElementUtils.hasAnnotation(beanType, RequestMapping.class));
             */

            //去掉RequestMapping
            return (AnnotatedElementUtils.hasAnnotation(beanType, Controller.class) ||
                    ( AnnotatedElementUtils.hasAnnotation(beanType, RequestMapping.class) && beanType.isInterface()==false )
            );
        }
    }
}

猜你喜欢

转载自blog.csdn.net/u013008898/article/details/111461004
今日推荐