首页 > 代码库 > 获得Spring容器

获得Spring容器

1. WebApplicationContext wac = ContextLoader.getCurrentWebApplicationCon; 

2. ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext();

3.

    public class Springfactory implements BeanFactoryAware {                private static BeanFactory beanFactory;                // private static ApplicationContext context;                public void setBeanFactory(BeanFactory factory) throws BeansException {              this.beanFactory = factory;          }                /**          * 根据beanName名字取得bean          *           * @param beanName          * @return          */          public static <T> T getBean(String beanName) {              if (null != beanFactory) {                  return (T) beanFactory.getBean(beanName);              }              return null;          }            }