我的 @Startup 单例未在 JavaEE 应用程序中启动

发布于 2025-01-02 23:06:01 字数 385 浏览 1 评论 0原文

我得到了以下单例代码:

@javax.ejb.Singleton
@javax.ejb.Startup
public class SingletonWhichIsSupposedToStart {

  @PostConstruct
  public void ready(){
  //there is a breakpoint on the next line
  System.out.println("singleton ready");
  }
}

但是当我以调试模式(在 Glassfish3 上)启动应用程序时,既没有打印“单例就绪”,也没有触发断点。有什么建议吗?

编辑:似乎该类已部署,并且可以注入,但生命周期方法 @PostConstruct 被忽略。

I got the following Singleton code:

@javax.ejb.Singleton
@javax.ejb.Startup
public class SingletonWhichIsSupposedToStart {

  @PostConstruct
  public void ready(){
  //there is a breakpoint on the next line
  System.out.println("singleton ready");
  }
}

But when I start the application in debug mode (on Glassfish3), nor the 'singleton ready' is printed, nor the breakpoint is triggered. Any suggestions?

EDIT: Seems that the class is deployed, and can be injected, but the lifecycle method @PostConstruct is ignored.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文