尝试在演示代码上进行操作 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";
}
}
答案 0 :(得分:3)
HelloController
需要定义为位于程序包中。如果您完全按照指南进行操作,请尝试以下操作,
package example.helloworld;
import io.micronaut.http.annotation.*;
@Controller("/hello")
public class HelloController {
@Get
public String index() {
return "Hello World";
}
}