SaTokenListener 自定义全局侦听器加载顺序问题
- Dominant language
- Java
- Stars
- 19k
- Forks
- 2.9k
- PR merge metrics
- No merged PRs in 30d
Description
### 使用版本:
sa-token - 1.39.0
spring boot - 3.3.3
### 涉及的功能模块:
- 全局侦听器 SaTokenListener
- Redis集成 SaTokenDao
- jackson组件 SaTokenDaoRedisJackson
### 测试步骤:
+ 我经过以下步骤测试:
使用 `@Component` 注册了一个自定义的全局侦听器,并监听全局组件注册事件 `doRegisterComponent`。代码如下:
```java
@Component
public class MySaTokenListener extends SaTokenListenerForSimple {
@Override
public void doRegisterComponent(String compName, Object compObj) {
System.out.println("compName = " + compName);
}
}
```
+ 项目启动后得出以下结果:
```
2024-09-20T15:31:47.071+08:00 INFO 13976 --- [ main] w.j.f.config.satoken.SaLogForSlf4j : 全局组件 SaLog 载入成功: work.jiuri.framework.config.satoken.SaLogForSlf4j
2024-09-20T15:31:47.074+08:00 INFO 13976 --- [ main] w.j.f.config.satoken.SaLogForSlf4j : 全局配置 SaTokenConfig [tokenName=jiuri-admin2-token, timeout=86400, activeTimeout=1800, dynamicActiveTimeout=false, isConcurrent=true, isShare=true, maxLoginCount=12, maxTryTimes=12, isReadBody=true, isReadHeader=true, isReadCookie=true, isWriteHeader=false, tokenStyle=uuid, dataRefreshPeriod=30, tokenSessionCheckLogin=true, autoRenew=true, tokenPrefix=null, isPrint=false, isLog=true, logLevel=trace, logLevelInt=1, isColorLog=true, jwtSecretKey=null, httpBasic=, httpDigest=, currDomain=null, sameTokenTimeout=86400, checkSameToken=false, cookie=SaCookieConfig [domain=null, path=null, secure=false, httpOnly=false, sameSite=null], sign=SaSignConfig [secretKey=null, timestampDisparity=900000]]
2024-09-20T15:31:47.077+08:00 INFO 13976 --- [ main] w.j.f.config.satoken.SaLogForSlf4j : 全局组件 SaTokenDao 载入成功: cn.dev33.satoken.dao.SaTokenDaoRedisJackson
2024-09-20T15:31:47.078+08:00 INFO 13976 --- [ main] w.j.f.config.satoken.SaLogForSlf4j : 全局组件 SaTokenContext 载入成功: cn.dev33.satoken.spring.SaTokenContextForSpringInJakartaServlet
2024-09-20T15:31:47.080+08:00 INFO 13976 --- [ main] w.j.f.config.satoken.SaLogForSlf4j : 全局组件 SaJsonTemplate 载入成功: cn.dev33.satoken.spring.json.SaJsonTemplateForJackson
compName = SaJsonTemplate
```
可以看到只有最后注册的 `SaJsonTemplate` 组件,才会被正常侦听。
通过debug发现自定义的侦听器并不是最先注册的,所以在注册之前发生的事件无法被正常侦听到
### 疑问
`SaTokenEventCenter.registerListener(new MySaTokenListener());` 手动注册的没有这个问题。
是否可以提高通过 `@Component` 注册的自定义侦听器的的优先级,或者是否有其他方法可以手动提高优先级。
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by tracing @Component listener discovery and SaTokenEventCenter.registerListener during startup, then reproduce the registration sequence involving SaTokenListener, SaTokenDaoRedisJackson, and SaJsonTemplate. Done means a component listener registered through @Component observes the relevant global component events, or the supported way to control listener order is documented.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, redis, spring-boot
- Domain
- authentication, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100