You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
package com.config ;
import org.springframework.context.annotation.Bean ;
import org.springframework.context.annotation.Configuration ;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry ;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry ;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport ;
import com.interceptor.AuthorizationInterceptor ;
@Configuration
public class InterceptorConfig extends WebMvcConfigurationSupport {
@Bean
public AuthorizationInterceptor getAuthorizationInterceptor ( ) {
return new AuthorizationInterceptor ( ) ;
}
@Override
public void addInterceptors ( InterceptorRegistry registry ) {
registry . addInterceptor ( getAuthorizationInterceptor ( ) ) . addPathPatterns ( "/**" ) . excludePathPatterns ( "/static/**" ) ;
super . addInterceptors ( registry ) ;
}
/**
* springboot 2.0配置WebMvcConfigurationSupport之后, 会导致默认配置被覆盖, 要访问静态资源需要重写addResourceHandlers方法
*/
@Override
public void addResourceHandlers ( ResourceHandlerRegistry registry ) {
registry . addResourceHandler ( "/**" )
. addResourceLocations ( "classpath:/resources/" )
. addResourceLocations ( "classpath:/static/" )
. addResourceLocations ( "classpath:/admin/" )
. addResourceLocations ( "classpath:/front/" )
. addResourceLocations ( "classpath:/public/" ) ;
super . addResourceHandlers ( registry ) ;
}
}