EJB中的调用方法在JBoss启动时 [英] Call method in EJB on JBoss startup
问题描述
我正在寻找部署在JBoss上的EJB中的一个入口点。
I'm looking for an entry point in an EJB deployed on JBoss.
Servlet具有启动加载
标签用于其 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.
推荐答案
在3.1之前,EJB不存在。使用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.
这篇关于EJB中的调用方法在JBoss启动时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!