提交 | 用户 | 时间
|
94c44e
|
1 |
package com.iailab.module.shasteel.util; |
D |
2 |
|
|
3 |
import org.springframework.beans.BeansException; |
|
4 |
import org.springframework.context.ApplicationContext; |
|
5 |
import org.springframework.context.ApplicationContextAware; |
|
6 |
import org.springframework.stereotype.Component; |
|
7 |
|
|
8 |
/** |
|
9 |
* Spring Context 工具类 |
|
10 |
* |
|
11 |
* @author Mark sunlightcs@gmail.com |
|
12 |
*/ |
|
13 |
@Component |
|
14 |
public class SpringContextUtils implements ApplicationContextAware { |
|
15 |
public static ApplicationContext applicationContext; |
|
16 |
|
|
17 |
@Override |
|
18 |
public void setApplicationContext(ApplicationContext applicationContext) |
|
19 |
throws BeansException { |
|
20 |
SpringContextUtils.applicationContext = applicationContext; |
|
21 |
} |
|
22 |
|
|
23 |
public static Object getBean(String name) { |
|
24 |
return applicationContext.getBean(name); |
|
25 |
} |
|
26 |
|
|
27 |
public static <T> T getBean(Class<T> requiredType) { |
|
28 |
return applicationContext.getBean(requiredType); |
|
29 |
} |
|
30 |
|
|
31 |
public static <T> T getBean(String name, Class<T> requiredType) { |
|
32 |
return applicationContext.getBean(name, requiredType); |
|
33 |
} |
|
34 |
|
|
35 |
public static boolean containsBean(String name) { |
|
36 |
return applicationContext.containsBean(name); |
|
37 |
} |
|
38 |
|
|
39 |
public static boolean isSingleton(String name) { |
|
40 |
return applicationContext.isSingleton(name); |
|
41 |
} |
|
42 |
|
|
43 |
public static Class<? extends Object> getType(String name) { |
|
44 |
return applicationContext.getType(name); |
|
45 |
} |
|
46 |
|
|
47 |
} |