首页 > 解决方案 > 从 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的方法,并且@Pathcontext.getUtiInfoContainerRequestContext.

这是最好和最有效的方法吗?

问候。

标签: javascalajava-8jerseyjax-rs

解决方案


推荐阅读