【问题标题】:Micronaut HelloWorld Error: Unexpected error: Illegal name .$HelloControllerDefinitionMicronaut HelloWorld 错误:意外错误:非法名称 .$HelloControllerDefinition
【发布时间】:2019-02-05 02:47:27
【问题描述】:

尝试在 https://docs.micronaut.io/latest/guide/index.html#creatingServer上继续演示代码

步骤如下: src/main/java/example/helloworld/HelloController.java

出现错误:

> Task :compileJava FAILED
Note: Creating bean classes for 1 type elements
error: Unexpected error: Illegal name .$HelloControllerDefinition
1 error

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':compileJava'.
> Compilation failed; see the compiler error output for details.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 7s
1 actionable task: 1 executed

我知道还有一个与此相关的问题,但没有答案 error: Unexpected error: Illegal name .$HelloControllerDefinition

我该怎么办?

和 hellocontroller 完全按照文档所述

import io.micronaut.http.annotation.*;

@Controller("/hello") 
public class HelloController {
    @Get 
    public String index() {
        return "Hello World"; 
    }
}

【问题讨论】:

  • HelloController.java 文件是什么样的?
  • 就像上面的演示一样。我已经编辑了我的问题并添加了代码

标签: micronaut


【解决方案1】:

HelloController 需要定义在一个包中。如果您完全按照指南进行操作,请尝试以下操作,

package example.helloworld;

import io.micronaut.http.annotation.*;

@Controller("/hello") 
public class HelloController {
    @Get 
    public String index() {
        return "Hello World"; 
    }
}

【讨论】:

  • 问题已解决。非常感谢。ps。但是在官方文档中,真的没有这行。
  • +1000 最后评论。我正在尝试 micronaut 只是为了看看它是否值得学习,并且几乎停在这一点上,因为它没有通过我的“5 分钟测试”——如果某些产品在文档中的第一个演示应用程序无法按原样运行——这通常预示着更多的问题即将到来。
猜你喜欢
  • 2018-12-06
  • 1970-01-01
  • 2016-05-16
  • 2020-06-15
  • 1970-01-01
  • 2019-02-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多