首页 > 解决方案 > @Controller 的元注释在 Micronaut 中不起作用

问题描述

我正在尝试实现@Controller如下的自定义注释(元注释):

@MustBeDocumented
@Retention(AnnotationRetention.RUNTIME)
@Target(AnnotationTarget.CLASS)
@Secured(SecurityRule.IS_AUTHENTICATED)
@Controller
annotation class CustomController(

    @get:AliasFor(annotation = Controller::class)
    val value: String
)

//Usage:

@CustomController("/demo-api")
class ChangeController(private val changeGroupApi: ChangeGroupApi) {

   //...
}

但是,Micronaut 的行为就好像控制器类根本没有注释一样。见相关日志,类未注解时同理。

相关日志:

10:56:47.351 [default-nioEventLoopGroup-1-2] DEBUG i.m.s.rules.InterceptUrlMapRule - One or more of the IP patterns matched the host address [127.0.0.1]. Continuing request processing.
10:56:47.352 [default-nioEventLoopGroup-1-2] DEBUG i.m.s.rules.InterceptUrlMapRule - No url map pattern exact match found for path [/demo-api] and method [GET]. Searching in patterns with no defined method.
10:56:47.352 [default-nioEventLoopGroup-1-2] DEBUG i.m.s.rules.InterceptUrlMapRule - No url map pattern match found for path [/demo-api]. Returning unknown.
10:56:47.352 [default-nioEventLoopGroup-1-2] DEBUG i.m.security.filters.SecurityFilter - Authorized request GET /demo-api. No rule provider authorized or rejected the request.

有什么想法让它发挥作用吗?

标签: kotlinannotationsmicronaut

解决方案


推荐阅读