1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| public final class SpringCtx { private SpringCtx() { } private static ApplicationContext context = new ClassPathXmlApplicationContext("/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; } }
|