Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

过滤器不生效 #1477

Closed
sunjinghan7331 opened this issue Dec 20, 2019 · 5 comments
Closed

过滤器不生效 #1477

sunjinghan7331 opened this issue Dec 20, 2019 · 5 comments

Comments

@sunjinghan7331
Copy link

按照官方指导的spi方式配置了过滤器,但是没有生效,请问有什么原因?也没有报任何的错误

@yhs0092
Copy link
Member

yhs0092 commented Dec 21, 2019

是不是SPI配置文件写漏了呢?
Java-Chassis使用SPI机制加载扩展的时候会打印日志,可以参考一下这里的评论检查一下日志。

@sunjinghan7331
Copy link
Author

我在resources文件夹下新建了META-INF/services/org.apache.servicecomb.common.rest.filter.HttpServerFilter 文件,里面以包名+类名的全路径方式指定了我的过滤器,过滤器类实现了HttpServerFilter,并且在afterReceiveRequest()方法中打印一行控制台信息。

微服务运行后收到请求,日志中有如下信息:
[2019-12-23 09:21:50,886][INFO][vert.x-eventloop-thread-8][SPIServiceUtils.java][]Found SPI service javax.ws.rs.core.Response$StatusType, count=0. org.apache.servicecomb.foundation.common.utils.SPIServiceUtils.loadSortedService(SPIServiceUtils.java:79)
[2019-12-23 09:21:50,889][INFO][vert.x-eventloop-thread-8][SPIServiceUtils.java][]Found SPI service org.apache.servicecomb.core.tracing.TraceIdGenerator, count=1. org.apache.servicecomb.foundation.common.utils.SPIServiceUtils.loadSortedService(SPIServiceUtils.java:79)
[2019-12-23 09:21:50,889][INFO][vert.x-eventloop-thread-8][SPIServiceUtils.java][] 0. org.apache.servicecomb.core.tracing.BraveTraceIdGenerator. org.apache.servicecomb.foundation.common.utils.SPIServiceUtils.loadSortedService(SPIServiceUtils.java:82)
没有我自定义的过滤器类,同时自定义的过滤器也没有生效。请看一下是什么问题

@liubao68
Copy link
Contributor

配置正确一般日志会打印loadSortedService,然后下面有你的类的名字。没有的话,看看services文件的名称,目录名称等是不是有误,导致JDK没有加载到对应的文件。

@sunjinghan7331
Copy link
Author

重新配置了过滤器文件,过滤器生效了,谢谢

@hule123
Copy link

hule123 commented Jul 29, 2021

重新配置了过滤器文件,过滤器生效了,谢谢

怎么重新配置的

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants