There are some ways to do, such as using Servletcontextlistener, startup Servlets (see load-on-startup
in specification), Resource Adapters in environments full profile, EJB 3.1 @Startup, etc..
The decision of which to use varies from project to project and the various approaches the most common are these:
@WebListener
public class YourStartupApplication implements ServletContextListener {
@Inject
private Service service;
@Override
public void contextInitialized(final ServletContextEvent sce) {
service.doSomethingOnStartup();
}
@Override
public void contextDestroyed(final ServletContextEvent sce) {
service.doSomethingOnShutdown();
}
}
@Startup
@Singleton
public class YourStartupApplication {
@Inject
private Service service;
@PostConstruct
public void startup() {
service.doSomethingOnStartup();
}
@PreDestroy
public void shutdown() {
service.doSomethingOnShutdown();
}
}
Have you tried using a Servletcontextlistener?
– adelmo00
Yes, just like that =)
– SoabTI