问题描述
我不明白什么时候应该使用 @Controller
,什么时候应该使用 @Endpoint
来使用 Micronaut 框架创建端点。
在 documentation 之后,我创建了一项服务并通过以下方式在 /endpoint
上提供:
@Controller("/endpoint")
public class DummyService {
@Get
@Produces(MediaType.TEXT_PLAIN)
public String index() {
return "Hello World!";
}
}
但是 here 它是用 @Endpoint
注释创建的:
@Endpoint("/endpoint")
public class DummyService {
@Get
@Produces(MediaType.TEXT_PLAIN)
public String index() {
return "Hello World!";
}
}
创建服务并使其在 Micronaut 中的端点可用的正确方法是什么?
如果这个问题是由于对更基本的概念缺乏了解而产生的,您能否提供参考?
解决方法
2021-04-13T09:32:12.912262+00:00 host2 postgres_2[13527]: [7-1] pid=13527,session=6075651c.34d7,line=1,sqlstate=42704,user_app=sub1,user=bpuser,db=testdb,client=10.186.34.182,txId=0 ERROR: replication slot "pgl_testdb_pgnode_pdaaa79d_sub1" does not exist
应该用于管理端点(调整日志级别、管理缓存、监控资源利用率等),而不是应用程序功能。 @Endpoint
应用于不属于管理和监控的应用端点。
编辑
要解决特别提出的问题:
创建服务并使其在 Micronaut 中的端点可用的正确方法是什么?
一般来说,这样做的方法是将一个 bean 添加到作为您的服务的应用程序上下文中,然后让 DI 容器在需要的地方注入该 bean。
@Controller