Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save pmuir/638308 to your computer and use it in GitHub Desktop.
Save pmuir/638308 to your computer and use it in GitHub Desktop.
// uncomment line if you want the instance to be retained in application scope
// @ApplicationScoped
public class ApplicationInitializer
{
public void onStartup(@Observes @Initialized Object ctx)
{
System.out.println("Initialized application with context" + ctx);
}
}
@Qualifier
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.FIELD, ElementType.PARAMETER})
public @interface Destroyed {}
@Qualifier
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.FIELD, ElementType.PARAMETER})
public @interface Initialized {}
@WebListener
public class ServletContextLifecycleNotifier implements ServletContextListener
{
@Inject @Any
private Event<ServletContext> servletContextEvent;
@Override
public void contextInitialized(ServletContextEvent sce)
{
servletContextEvent.select(new AnnotationLiteral<Initialized>() {}).fire(sce.getServletContext());
}
@Override
public void contextDestroyed(ServletContextEvent sce)
{
servletContextEvent.select(new AnnotationLiteral<Destroyed>() {}).fire(sce.getServletContext());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment