Kotlin CDI拦截器未被调用

问题描述 投票:1回答:1

我试图通过移植一些现有的Java代码来了解Kotlin以查看差异。我正在尝试编写一个简单的CDI Interceptor,它允许我记录带注释的方法的开始和结束。我的拦截器和注释看起来像这样:

import javax.interceptor.InterceptorBinding

@InterceptorBinding
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION, AnnotationTarget.TYPE)
@Retention(AnnotationRetention.RUNTIME)
@MustBeDocumented
annotation class Logged {

}



import org.apache.log4j.Logger
import javax.interceptor.AroundInvoke
import javax.interceptor.Interceptor
import javax.interceptor.InvocationContext

@Interceptor
@Logged
class LoggingInterceptor {

    @AroundInvoke
    fun logFunctionDetails(context: InvocationContext): Any  {
        print("logFunctionDetails - start")

        // TODO Implement method

        print("logFunctionDetails - end")
        return context.proceed()
    }
}

我还有一个用@Logged注释的简单JAX-RS端点。它看起来像这样:

@Path("/healthCheck")
@Stateless
@Logged
open class HealthCheckRS : AbstractRestService() {

    @Path("/")
    @GET
    @POST
    @PUT
    @DELETE
    @HEAD
    @OPTIONS
    @Logged
    open fun healthCheck(): String {
        return "" + System.currentTimeMillis()
    }
}

我期待看到我的LoggingInterceptor函数被调用,但它完全绕过了拦截器。为了让这个在Kotlin工作,还有什么我需要做的吗?我有类似的代码,在Java中工作没有问题。

java kotlin cdi interceptor
1个回答
0
投票

归功于Siliarus:您的拦截器是否已启用?我看到你的拦截器上没有@Priority(你没有提到beans.xml)。

这个答案是一个占位符,因此这个问题不再列在未回答的问题上。事实上,评论是解决方案。

© www.soinside.com 2019 - 2024. All rights reserved.