Micronaut 控制器错误页面未找到

Micronaut controller error Page Not Found

我使用以下方法创建了一个新的 micronaut 应用程序 mn 创建应用程序 example.micronaut.complete

之后,我使用 intellij 打开了项目,并添加了一个新的 class 作为 TestController 到项目中,代码如下:

package example.micronaut;
import io.micronaut.http.MediaType;
import io.micronaut.http.annotation.Controller;
import io.micronaut.http.annotation.Get;


@Controller("/hello")
public class TestController {

TestController(){}

@Get(value = "/", produces = MediaType.TEXT_PLAIN)
String getTest(){
    return "some string";
   }
}

但我得到

{"_links":{"self":{"href":"/","templated":false}},"message":"Page Not Found"}

每当我尝试访问 /hello 端点时

我的 application.yml 看起来像这样:

micronaut:
    application:
        name: complete
    server:
        port: 8080

没有看到更多你的项目,很难说错在哪里。我已将您的代码直接粘贴到一个项目中,它按预期工作。查看 https://github.com/jeffbrown/khwaja404. The controller at https://github.com/jeffbrown/khwaja404/blob/a3e57623ed5b30e28eb95bfe0f4a4a5c9d123fd8/src/main/java/example/micronaut/TestController.java 处的项目工作正常...

package example.micronaut;

import io.micronaut.http.MediaType;
import io.micronaut.http.annotation.Controller;
import io.micronaut.http.annotation.Get;


@Controller("/hello")
public class TestController {

    // this empty constructor is not
    // needed, but isn't a problem...
    TestController() {
    }

    @Get(value = "/", produces = MediaType.TEXT_PLAIN)
    String getTest() {
        return "some string";
    }
}

端点响应:

$ curl http://localhost:8080/hello
some string

需要注意的一件事是您可能缺少 micronaut-inject-java and/or micronaut-inject 依赖项,如 https://github.com/jeffbrown/khwaja404/blob/a3e57623ed5b30e28eb95bfe0f4a4a5c9d123fd8/build.gradle#L27-L29.

中所述

另一个是,如果您是 运行 来自 IDE 的应用程序(如 IntelliJ IDEA),请确保您在构建中启用了注释处理器。

折腾了一整天才发现是Eclipse的bug,最新版本已经解决了。请切换到版本:2020-12 (4.18.0)或以上

Issue Description

Eclipse Bug