代码
package com.itgacl.magic4j.common.config;
import com.itgacl.magic4j.libcommon.component.resolver.Magic4jMethodArgumentResolver;
import com.itgacl.magic4j.common.interceptor.LoginInterceptor;
import com.itgacl.magic4j.common.interceptor.NotEmptyInterceptor;
import com.itgacl.magic4j.common.interceptor.AuthInterceptor;
import com.itgacl.magic4j.libcommon.interceptor.AutoIdempotentInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.OrderComparator;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import java.util.List;
/**
* springBoot2后,使用WebMvcConfigurer添加拦截器
*/
@Configuration
public class Magic4jWebMvcConfigurer implements WebMvcConfigurer{
// 设置一个路径前缀来匹配controller中的方法,
// 在Spring初始化阶段,如果第二个参数检测结果返回为true则
// "/prefix"会作为一个前缀添加到requestMapping的前面,
// 比如方法上的RequestMapping的注解为"/method",则这个方法
// 最终的匹配路径是"/prefix/method"
// 初始化的地方为 RequestMappingHandler.getPathPrefix()
@Override
public void configurePathMatch(PathMatchConfigurer configurer) {
configurer
.addPathPrefix("/stage",(aClass) -> true);
}
}
参考资料
SpringBoot2.x 给Controller的RequestMapping添加统一前缀