java - 从 JAX-RS 注解中获取注解信息
问题描述
我正在使用 JAX-RS 请求过滤器,其中我的端点注释 @Country 包含我的过滤器需要做一些事情的国家的一些信息。
@GET
@Path("/country")
@Country("ESP")
public Future<String> countryResource(Future<String> future) throws Exception {
所以现在我的过滤器被调用,因为这个方法包含相同的过滤器
@Priority(3)
@Primary
@Provider
@Country
class CountryFilter extends ContainerRequestFilter {
override def filter(context: ContainerRequestContext): Unit = {
//Here I need to get the "ESP" from the endpoint annotation
}
}
我不是专家,JAX-RS
但我怀疑是否有可能知道我的端点注释的信息,但由于过滤器仅在方法添加注释的情况下被调用,我只是想知道是否有任何魔法这里。
现在我只是reflexion
用来查找所有注释为@Country
的方法,并且@Path
它context.getUtiInfo
与ContainerRequestContext
.
这是最好和最有效的方法吗?
问候。
解决方案
推荐阅读
- java - 如何在具有相同 JPanel 内容的不同类中设置两个 JScrollPanes
- mongodb - 副本集设置为 true 的 stable/mongodb helm chart 身份验证问题
- postgresql - 如何通过 Spark 中的 jdbc 连接到 docker 托管的 postgresql 数据库?
- python - 有没有更简单的方法来确保列表中的值从一个 elif 语句延续到另一个?
- python - 我需要显示第三个
- 在美丽汤
- python-3.x - 如何从嵌套字典中检索所有“组”
- c# - 即使在控制器中设置了 AllowGet,GET 请求也会被阻止
- tkinter - 如何使用 tkinter 设置在特定时间执行的命令
- php - 如何用 preg_replace_callback 替换这个 preg_replace 以实现 php 5.6 兼容性
- java - 如果值为null,Map可以在调用get方法时阻塞线程吗?