Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

It's my annotation class:

@Target(AnnotationTarget.FUNCTION)
@Retention(AnnotationRetention.RUNTIME)
annotation class ExternalCallMonitor(val system: String, val function: String)

Using SpEL to set annotation value as follows;

    @ExternalCallMonitor(system = "#{@url.getHost()}", function = "#{@url.getPath()}")
    fun methodWithUrlParameter(url: URL) {
        // Do nothing
    }

Trying to get value in the Aspect as follows

@Around("@annotation(aspect.external.ExternalCallMonitor)")
@Throws(Throwable::class)
fun externalCallMonitor(joinPoint: ProceedingJoinPoint): Any? {
    val methodName = joinPoint.signature.name
    val signature = joinPoint.signature as MethodSignature
    val method = joinPoint.target.javaClass.getMethod(signature.method.name, URL::class.java)
    val annotation = method.getAnnotation(ExternalCallMonitor::class.java)
    val host = annotation.system

host should be localhost here but I am getting "#{@url.getHost()}"

question from:https://stackoverflow.com/questions/65842885/using-spel-as-annotation-value

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
556 views
Welcome To Ask or Share your Answers For Others

Please log in or register to answer this question.

Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...