IOC依赖注入,配置bean。创建需要的实例,不过在相对应的类中应该有set方法。set注入比较方便,也简单。private static ApplicationContext ctx = new ClassPathXmlApplicationContext("spring/spring-servlet.xml"); public static Object getBean(String beanName){ return ctx.getBean(beanName); }