Skip to content

Instantly share code, notes, and snippets.

@matthewbednarski
Created September 24, 2015 10:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matthewbednarski/a65ef94f5b158059e563 to your computer and use it in GitHub Desktop.
Save matthewbednarski/a65ef94f5b158059e563 to your computer and use it in GitHub Desktop.
gives access to the ApplicationContext
package it.solinfo.xdsindexer.utils;
import org.apache.log4j.Logger;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import javax.inject.Named;
/**
* Created by arch on 4/9/15.
*/
@Named
public class AppContext implements ApplicationContextAware{
protected final Logger log = Logger.getLogger(getClass());
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
log.debug("Setting context with: " + applicationContext);
AppContext.ctx = applicationContext;
}
private static ApplicationContext ctx;
/**
* Get access to the Spring ApplicationContext from everywhere in your Application.
*
* @return
*/
public static ApplicationContext getApplicationContext() {
return ctx;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment