30 lines
796 B
Java
30 lines
796 B
Java
package com.iconplus.smartproc.helper.context;
|
|
|
|
import org.springframework.beans.BeansException;
|
|
import org.springframework.context.ApplicationContext;
|
|
import org.springframework.context.ApplicationContextAware;
|
|
|
|
public class ContextProvider implements ApplicationContextAware {
|
|
|
|
private static ApplicationContext CONTEXT;
|
|
|
|
@Override
|
|
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
|
CONTEXT = applicationContext;
|
|
}
|
|
|
|
/**
|
|
* Get a Spring bean by type.
|
|
**/
|
|
public static <T> T getBean(Class<T> beanClass) {
|
|
return CONTEXT.getBean(beanClass);
|
|
}
|
|
|
|
/**
|
|
* Get a Spring bean by name.
|
|
**/
|
|
public static Object getBean(String beanName) {
|
|
return CONTEXT.getBean(beanName);
|
|
}
|
|
|
|
} |