Fix when duplication spi class found using SpiLoader #3387
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Describe what this PR does / why we need it
跟#3377 相同,补充申请PR提交到1.8分支
当项目jar依赖包里有重复sentinel包,目前
SpiLoader
加载META-INF/services
里的SPI扩展类,如果发现有重复的已解析过的扩展类,会抛出异常提示,导致相关功能无法运行。这种场景可能更好的处理方式是程序不抛异常,在日志中记录该情况便于排查,已解析过的扩展类跳过处理,让程序正常运行。
Does this pull request fix one issue?
Fixes #3376
Describe how you did it
SpiLoader
里的classMap
存储了已解析的扩展类,其中value类型为Class
,可通过value来检查重复。Describe how to verify it
1.在spring-webmvc的demo里,添加
META-INF/services
目录,拷贝sentinel-core里的部分配置,启动WebMvcDemoApplication
类,访问接口测试并检查日志情况。2.在项目里引用2个不同版本的
sentinel-core
,启动项目进行限流相关测试。Special notes for reviews
优化了该类的一些日志打印,打印出SPI扩展文件地址,用于日志排查。