Forked from mojavelinux/ApplicationInitializer.java
Created
October 21, 2010 11:16
-
-
Save pmuir/638308 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Qualifier | |
@Retention(RetentionPolicy.RUNTIME) | |
@Target({ElementType.FIELD, ElementType.PARAMETER}) | |
public @interface Destroyed {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Qualifier | |
@Retention(RetentionPolicy.RUNTIME) | |
@Target({ElementType.FIELD, ElementType.PARAMETER}) | |
public @interface Initialized {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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