| | |
| | | public class SpringContextHolder implements ApplicationContextAware { |
| | | |
| | | /** |
| | | * 以静态变量保存ApplicationContext,可在任意代码中取出ApplicaitonContext. |
| | | * 以静态变量保存ApplicationContext,可在任意代码中取出ApplicaitonContext. |
| | | */ |
| | | private static ApplicationContext context; |
| | | |
| | | /** |
| | | * 实现ApplicationContextAware接口的context注入函数, 将其存入静态变量. |
| | | * 实现ApplicationContextAware接口的context注入函数, 将其存入静态变量. |
| | | */ |
| | | |
| | | @Override |
| | |
| | | } |
| | | |
| | | /** |
| | | * 获取applicationContext |
| | | * 获取applicationContext |
| | | * @return |
| | | */ |
| | | public ApplicationContext getApplicationContext() { |
| | |
| | | } |
| | | |
| | | /** |
| | | * 通过name获取 Bean. |
| | | * 通过name获取 Bean. |
| | | * @param name |
| | | * @return |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * 通过class获取Bean. |
| | | * 通过class获取Bean. |
| | | * @param <T> |
| | | * @param clazz |
| | | * @return |
| | |
| | | } |
| | | |
| | | /** |
| | | * 通过class获取Bean. |
| | | * 通过class获取Bean. |
| | | * @param clazz |
| | | * @param <T> |
| | | * @return |
| | |
| | | } |
| | | |
| | | /** |
| | | * 通过name,以及Clazz返回指定的Bean |
| | | * 通过name,以及Clazz返回指定的Bean |
| | | * @param name |
| | | * @param clazz |
| | | * @param <T> |