Created
January 7, 2020 22:04
-
-
Save schroedermatt/f895a75c121245dcc1ce9280a46eb913 to your computer and use it in GitHub Desktop.
Spring utility class to bridge between Spring and Non-Spring things.
This file contains hidden or 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
@Component | |
public class SpringContext implements ApplicationContextAware { | |
private static ApplicationContext context; | |
@Override | |
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { | |
context = applicationContext; | |
} | |
public static <T> T getBean(Class<T> beanClass) { | |
return context.getBean(beanClass); | |
} | |
public static <T> T getBean(String beanName, Class<T> beanClass) { | |
return (T)context.getBean(beanName); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment