package com.fengjx.ttwx.common.system.init;

import javax.servlet.ServletContext;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.web.context.ContextLoader;
import org.springframework.web.context.support.WebApplicationContextUtils;

public class SpringBeanFactoryUtil {

    private static ApplicationContext springContext;

    private static ServletContext servletContext;

    public static void setServletContext(ServletContext servletContext) {
        SpringBeanFactoryUtil.servletContext = servletContext;
    }

    private static ApplicationContext getSpringContext() {
        if (springContext == null) {
            if (servletContext != null) {
                springContext = WebApplicationContextUtils.getWebApplicationContext(servletContext);
            } else {
                springContext = ContextLoader.getCurrentWebApplicationContext();
            }
            if (springContext == null) {
                springContext = new ClassPathXmlApplicationContext("applicationContext.xml");
            }
        }
        return springContext;
    }

    public static Object getBean(String beanName) {
        return getSpringContext().getBean(beanName);
    }

    public static <T> T getBean(Class<T> cls) {
        return getSpringContext().getBean(cls);
    }
}

@@ -1,8 +1,9 @@
+%0A
 package 
@@ -43,46 +43,8 @@
 t;%0A%0A
-import javax.servlet.ServletContext;%0A%0A
 impo
@@ -299,16 +299,54 @@
 Utils;%0A%0A
+import javax.servlet.ServletContext;%0A%0A
 public c
@@ -1197,14 +1197,13 @@
 tic 
-Object
+%3CT%3E T
  get
@@ -1232,32 +1232,36 @@
 %7B%0A        return
+ (T)
  getSpringContex

修改getBean，支持泛型~