JBoss 启动时 EJB 中的调用方法 [英] Call method in EJB on JBoss startup

查看:19
本文介绍了JBoss 启动时 EJB 中的调用方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 JBoss 上部署的 EJB 中寻找入口点.

I'm looking for an entry point in an EJB deployed on JBoss.

Servlets 有 load-on-startup 标签在它的 web.xml 中使用.

Servlets have the load-on-startup tag to use in its web.xml.

我正在为 EJB 寻找类似的 init() 功能.

I'm searching for similar init() functionality for an EJB.

推荐答案

EJB 直到 3.1 才存在.使用 EJB 3.1,您可以使用单例 bean 来模拟:

That didn't exist for EJB until 3.1. With EJB 3.1 you can use a singleton bean to simulate that:

来自应用程序启动/关闭回调:

   @Startup
   @Singleton
   public class FooBean {

       @PostConstruct 
       void atStartup() { ... }

       @PreDestroy
       void atShutdown() { ... }

   }

否则,您将需要依靠古老的技巧来使用 ServletContextInitializer.

Otherwise, you will need to rely on the good old trick to use a ServletContextInitializer.

有一些特定于应用程序的扩展,例如Glassfish 的生命周期侦听器.也许 JBoss 有这样的事情.

There are some application-specific extension, e.g. lifecycle listener for Glassfish. Maybe there's such a thing for JBoss.

但如果我是你,我会尽可能地依赖标准功能.非标准扩展的问题在于您永远不知道可以做什么或不可以做什么,例如你能不能开始交易等等.

But if I were you I would try to rely on standard features as much as possible. The problem with non-standard extension is that you never know exactly what can be done or not, e.g. can you start transaction or not, etc.

这篇关于JBoss 启动时 EJB 中的调用方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆