views:

270

answers:

3

Hello,

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

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

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

+5  A: 

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

From Application Startup / Shutdown Callbacks:

   1:  @Startup
   2:  @Singleton
   3:  public class FooBean {
   4:   
   5:    @PostConstruct 
   6:    void atStartup() { ... }
   7:   
   8:    @PreDestroy
   9:    void atShutdown() { ... }
  10:   
  11:  }

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

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.

ewernli
Alternatively one can always use a MBean with start/stop lifecycle methods. The MBean is injected with the EJB needed and calls whatever methods from it that are required.
Bozhidar Batsov
Thanks.Two great posts. I ended up with a "ServletWrapper" instead. But a refactor is on the agenda.Cheers!
Elijah
A: 

Managed Beans can be used to do some process at JBoss startup, you have to add entry of that managed bean in configuration file.

Nayan Wadekar
A: 

You should be able to add the following line to the top of the method you want to run at startup:

@Observer("org.jboss.seam.postInitialization")
Andy