1 changed files with 37 additions and 0 deletions
@ -0,0 +1,37 @@
@@ -0,0 +1,37 @@
|
||||
# 解析框架笔记 |
||||
|
||||
@Primary注解是Spring框架中的一个注解,用于标识一个Bean作为默认的实现类 |
||||
|
||||
在Spring Boot 3.* 中,想要实行拦截器注入,可以使用以下方法来实现: |
||||
|
||||
```java |
||||
|
||||
@Configuration |
||||
public class SpringBootMvConfig implements SpringBootMvServer { |
||||
@Bean |
||||
public InterceptorRegistry interceptorRegistry() { |
||||
return new InterceptorRegistry(); |
||||
} |
||||
|
||||
@Override |
||||
public void addInterceptors(InterceptorRegistry registry) { |
||||
registry.addInterceptor(new SaInterceptor(handler->{ |
||||
SaRouter.match( |
||||
"/api/**").check(r-> StpUtil.checkLogin()); |
||||
SaRouter.match("/admin/**").check(r-> StpUtil.checkRole("admin")); |
||||
})) |
||||
.addPathPatterns("/**") |
||||
.excludePathPatterns("/acc/login", "/acc/isLogin", "/acc/logout"); |
||||
} |
||||
|
||||
@Bean |
||||
public StpLogic getStpLogicJwt() { |
||||
return new StpLogicJwtForSimple(); |
||||
} |
||||
} |
||||
``` |
||||
|
||||
这样就可以在Spring Boot 3.* 中实现了。 |
||||
|
||||
并且想要注册多个可以采用数组方式管理并统一注入。 |
||||
|
||||
Loading…
Reference in new issue