Created
September 25, 2015 10:19
-
-
Save BorzdeG/5399aa418397606c4895 to your computer and use it in GitHub Desktop.
get Application Context in not spring beans
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
import org.slf4j.Logger; | |
import org.slf4j.LoggerFactory; | |
import org.springframework.beans.BeansException; | |
import org.springframework.context.ApplicationContext; | |
import org.springframework.context.ApplicationContextAware; | |
import org.springframework.core.convert.ConversionService; | |
import org.springframework.stereotype.Component; | |
@Component | |
public class ApplicationContextProvider implements ApplicationContextAware { | |
@SuppressWarnings("unused") private static final Logger LOG = LoggerFactory.getLogger(ApplicationContextProvider.class.getName()); | |
private static ApplicationContext applicationContext = null; | |
public static ApplicationContext getApplicationContext() { | |
return applicationContext; | |
} | |
public static ConversionService getConversionService() { | |
return applicationContext.getBean("conversionService", ConversionService.class); | |
} | |
@Override | |
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { | |
LOG.trace("applicationContext: {}", applicationContext); | |
ApplicationContextProvider.applicationContext = applicationContext; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment