做springboot项目对token认证时,在application.properties做了配置
token:
tokenHeader: access-token
tokenSecret: 86f3d82fed2348f49b38ec86c1f2fed2
@Data
@Configuration
@ConfigurationProperties(prefix = "token")
public class TokenAuthenticationProperties {
private String tokenHeader;
private String tokenSecret;
@Override
public String toString() {
return "TokenAuthenticationProperties{" +
"tokenHeader='" + tokenHeader + '\'' +
", tokenSecret='" + tokenSecret + '\'' +
'}';
}
}
@Configuration
public class WebInterceptorConfiguration implements WebMvcConfigurer {
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new TokenInterceptor()).addPathPatterns("/**");
}
}
在这里我是用的是通过 @Autowired注入依赖
@Slf4j
@Component
public class TokenInterceptor