SpringCtx.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
public final class SpringCtx {
private SpringCtx() {
}

// Spring应用上下文环境
private static ApplicationContext context = new ClassPathXmlApplicationContext("/applicationContext.xml"); //new FileSystemXmlApplicationContext("classpath:applicationContext.xml");

public static <T> T getBean(Class<T> requiredType) {
T t = null;
try {
t = context.getBean(requiredType);
} catch (Exception e) {
e.printStackTrace();
}
return t;
}
}
文章目录