File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -11,6 +11,26 @@ groups and mounting, and the routing DSL.
1111
1212## Annotated routes
1313
14+ KSP collects every ` @Controller ` in the application into one generated object,
15+ ` neton.core.generated.GeneratedInitializer ` . ** Pass it to the framework explicitly** — it is
16+ not picked up on its own:
17+
18+ ``` kotlin
19+ import neton.core.generated.GeneratedInitializer
20+
21+ fun main (args : Array <String >) {
22+ Neton .run (args) {
23+ http { port = 8080 }
24+ routing { }
25+ modules(GeneratedInitializer ) // registers every @Controller route
26+ }
27+ }
28+ ```
29+
30+ If you forget this line, startup logs ` routing.no_routes ` and every controller endpoint answers
31+ 404 . Applications built from module manifests pass their modules the same way and add
32+ ` GeneratedInitializer ` alongside them for any controller declared in the application itself.
33+
1434### A basic controller
1535
1636Annotate a class with ` @Controller ` to give it a base path, then mark handlers with ` @Get ` ,
Original file line number Diff line number Diff line change @@ -11,6 +11,24 @@ Neton 提供两种方式定义路由:
1111
1212## 注解路由
1313
14+ KSP 会把应用里全部 ` @Controller ` 汇聚成一个生成对象 ` neton.core.generated.GeneratedInitializer ` 。
15+ ** 必须显式传给框架** ,它不会自己生效:
16+
17+ ``` kotlin
18+ import neton.core.generated.GeneratedInitializer
19+
20+ fun main (args : Array <String >) {
21+ Neton .run (args) {
22+ http { port = 8080 }
23+ routing { }
24+ modules(GeneratedInitializer ) // 注册全部 @Controller 路由
25+ }
26+ }
27+ ```
28+
29+ 漏了这一行,启动会打 ` routing.no_routes ` 告警,所有控制器接口都是 404。用模块清单组织的应用
30+ 本来就用 ` modules(...) ` 传模块,把 ` GeneratedInitializer ` 一并传入即可覆盖应用自身声明的控制器。
31+
1432### 基础控制器
1533
1634使用 ` @Controller ` 注解定义控制器类,指定基础路径。使用 ` @Get ` 、` @Post ` 等注解标记处理方法:
You can’t perform that action at this time.
0 commit comments