[英]@ServerEndpoint can be an EJB but can not be plain CDI bean?
I've just got a following problem and can not figure out an answer: 我刚遇到以下问题,无法找到答案:
@ServerEndpoint("/websocket/server")
public class ServerUpdateEndpoint implements Serializable {
...@OnOpen, OnMessage OnClose annoted methods, works fine...
@PostConstruct
public void start() {
logger.log(Level.INFO, "ServerUpdateEndpoint start");
}
@PreDestroy
public void stop() {
logger.log(Level.INFO, "ServerUpdateEndpoint stop");
}
}
When I annotate this class with @Named lifecycle callbacks @PostConstruct, @PreDestroy never gets executed. 当我使用@Named生命周期回调@PostConstruct注释此类时,@ PreDestroy永远不会执行。
When I annotate this with @Singleton it works fine. 当我用@Singleton注释它时,它可以正常工作。
Can anyone explain, what the problem with plain CDI annotations here? 任何人都可以在这里解释纯CDI注释的问题吗?
It definitely can have CDI annotations only. 它绝对只能具有CDI注释。 You'll need to annotate it
@ApplicationScoped
and ensure that a client connects to the endpoint. 您需要在
@ApplicationScoped
上注释它,并确保客户端连接到端点。 Were you giving it a scope when you added @Named
? 添加
@Named
时是否为它提供了作用域?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.