35 lines
1005 B
Java
35 lines
1005 B
Java
package com.labelsys.backend.config;
|
|
|
|
import com.labelsys.backend.interceptor.AuthInterceptor;
|
|
import lombok.RequiredArgsConstructor;
|
|
import org.springframework.context.annotation.Configuration;
|
|
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
|
|
|
/**
|
|
* Web MVC 配置类
|
|
* <p>
|
|
* 实现 WebMvcConfigurer 接口,配置 Spring MVC 拦截器等功能。
|
|
*/
|
|
@Configuration
|
|
@RequiredArgsConstructor
|
|
public class WebMvcConfig implements WebMvcConfigurer {
|
|
|
|
/**
|
|
* 认证拦截器
|
|
*/
|
|
private final AuthInterceptor authInterceptor;
|
|
|
|
/**
|
|
* 注册拦截器
|
|
* <p>
|
|
* 将认证拦截器注册到拦截器链中,拦截所有 `/api/**` 路径的请求。
|
|
*
|
|
* @param registry 拦截器注册器
|
|
*/
|
|
@Override
|
|
public void addInterceptors(InterceptorRegistry registry) {
|
|
registry.addInterceptor(authInterceptor).addPathPatterns("/api/**");
|
|
}
|
|
|
|
} |