import com.shop.interceptor.AuthorizationInterceptor;import com.shop.resolver.CurrentUserMethodArgumentResolver;import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.Configuration;import org.springframework.web.method.support.HandlerMethodArgumentResolver;import org.springframework.web.servlet.config.annotation.CorsRegistry;import org.springframework.web.servlet.config.annotation.EnableWebMvc;import org.springframework.web.servlet.config.annotation.InterceptorRegistry;import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;import java.util.List;@EnableWebMvc@Configurationpublic class WebMvcConfig extends WebMvcConfigurerAdapter { @Bean public HandlerInterceptorAdapter handlerInterceptorAdapter(){ return new AuthorizationInterceptor(); } @Bean public HandlerMethodArgumentResolver handlerMethodArgumentResolver(){ return new CurrentUserMethodArgumentResolver(); } @Override public void addInterceptors(InterceptorRegistry registry) { registry.addInterceptor(handlerInterceptorAdapter()).addPathPatterns("/**"); super.addInterceptors(registry); } @Override public void addCorsMappings(CorsRegistry registry) { registry.addMapping("/**"); super.addCorsMappings(registry); } @Override public void addArgumentResolvers(List argumentResolvers) { argumentResolvers.add(handlerMethodArgumentResolver()); super.addArgumentResolvers(argumentResolvers); }}
spring boot跨域
最新推荐文章于 2022-04-01 10:40:28 发布