package com.angkorteam.mbaas.server;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import javax.servlet.ServletContext;

/**
 * Created by socheat on 10/23/16.
 */
public class Spring {

    public static <T> T getBean(String name, Class<T> requiredType) throws BeansException {
        ServletContext servletContext = Application.get().getServletContext();
        ApplicationContext applicationContext = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
        return applicationContext.getBean(name, requiredType);
    }


    public static <T> T getBean(Class<T> requiredType) throws BeansException {
        ServletContext servletContext = Application.get().getServletContext();
        ApplicationContext applicationContext = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
        return applicationContext.getBean(requiredType);
    }

}

@@ -315,16 +315,74 @@
 ring %7B%0A%0A
+    private static ServletContext servletContext = null;%0A%0A
     publ
@@ -465,33 +465,37 @@
 ption %7B%0A        
-S
+if (s
 ervletContext se
@@ -484,32 +484,55 @@
 (servletContext 
+== null) %7B%0A            
 servletContext =
@@ -563,32 +563,42 @@
 rvletContext();%0A
+        %7D%0A
         Applicat
@@ -864,17 +864,21 @@
         
-S
+if (s
 ervletCo
@@ -875,32 +875,55 @@
 (servletContext 
+== null) %7B%0A            
 servletContext =
@@ -954,32 +954,42 @@
 rvletContext();%0A
+        %7D%0A
         Applicat

servlet context is null