Micronaut-超过1条路由与传入请求匹配

Micronaut-超过1条路由与传入请求匹配,micronaut,micronaut-rest,Micronaut,Micronaut Rest,我在测试控制器时遇到了一个问题,但我无法在一个简单的应用程序中重现这个问题。当我运行该应用程序时,它工作正常 我有一个控制器: 公共接口自动操作{ @岗位//Micronaut岗位 HttpResponse create(@NotNull@Valid@Body-TheCommand命令); } @控制器(“/home”) @安全(“用户”) @RequiredArgsConstructor//lombok @验证 公共类HomeController实现自动操作{ @凌驾 @鬼鬼祟祟的//lomb

我在测试控制器时遇到了一个问题,但我无法在一个简单的应用程序中重现这个问题。当我运行该应用程序时,它工作正常

我有一个控制器:

公共接口自动操作{
@岗位//Micronaut岗位
HttpResponse create(@NotNull@Valid@Body-TheCommand命令);
}
@控制器(“/home”)
@安全(“用户”)
@RequiredArgsConstructor//lombok
@验证
公共类HomeController实现自动操作{
@凌驾
@鬼鬼祟祟的//lombok
@ExecuteOn(TaskExecutors.IO)
公共HttpResponse create(@NotNull@Valid@Body-TheCommand命令){
返回HttpResponse.ok(…);
}
}
请注意,
@Post
注释位于界面中

此控制器的问题是路径
POST/home
不匹配。我发现问题出在
annotatedMethodoloteBuilder#过程(BeanDefinition定义,ExecutableMethod方法)
--
方法
没有HTTP映射(即最终
@Post

这是失败测试的输出:

    12:51:39.828 [nioEventLoopGroup-1-4] DEBUG DefaultTokenResolver - Request POST, /home, no token found.
    12:51:39.833 [nioEventLoopGroup-1-4] DEBUG Authenticator - com.example.controllers.DummyAuthenticationProvider
    12:51:39.835 [nioEventLoopGroup-1-4] INFO  DummyAuthenticationProvider - Successful dummy login [user]
    12:51:39.904 [nioEventLoopGroup-1-4] DEBUG SecurityFilter - Attributes: roles=>[user], username=>880f1a24-4997-40a6-bbf1-dde1f3871451
    12:51:39.905 [nioEventLoopGroup-1-4] DEBUG InterceptUrlMapRule - One or more of the IP patterns matched the host address [127.0.0.1]. Continuing request processing.
    12:51:39.908 [nioEventLoopGroup-1-4] DEBUG InterceptUrlMapRule - No url map pattern exact match found for path [/home] and method [POST]. Searching in patterns with no defined method.
    12:51:39.909 [nioEventLoopGroup-1-4] DEBUG InterceptUrlMapRule - No url map pattern match found for path [/home]. Returning unknown.
    12:51:39.910 [nioEventLoopGroup-1-4] DEBUG SecurityFilter - Authorized request POST /home. No rule provider authorized or rejected the request.

ControllerServerTest > testRegisterEntity() FAILED
    io.micronaut.http.client.exceptions.HttpClientResponseException: Forbidden
因此,我创建了这个测试:

//接收HomeController.class作为参数
void testController(最终类类型){
最终Bean定义定义=
this.context.getBeanDefinition(类型);
Assertions.assertNotNull(
定义.getAnnotation(Controller.class),
“控制器批注为空”
);
definition.getExecutableMethods()
.forEach(方法->{
if(!method.hasStereotype(Executable.class)){
返回;
}
//这两项都是失败的:
最终可选
More than 1 route matched the incoming request. The following routes matched /home: POST - /home, POST - /home
io.micronaut.http.client.exceptions.HttpClientResponseException: More than 1 route matched the incoming request. The following routes matched /home: POST - /home, POST - /home