public class Apputil implements Applicationcontextaware {private static ApplicationContext appctx;
/** * This method can inject the ApplicationContext object into the current class as a static member variable.
* * @param applicationcontext ApplicationContext Object * @throws org.springframework.beans.BeansException * * public void Setapplicationcontext (ApplicationContext applicationcontext) throws Beansexception {AP
PCTX = ApplicationContext; /** * This is a handy way to help us quickly get a bean * * @param beanname Bean's name * @return return a Bean object/pub
Lic static <T> T Getbean (String beanname) {checkapplicationcontext (APPCTX);
Return (T) Appctx.getbean (beanname); /** * for easy Unit Testing * @param applicationcontext * * private static void Checkapplicationcontext (Applic
Ationcontext applicationcontext) {if (Appctx = null) {synchronized (Apputil.class) {
if (ApplicationContext = = null) { Appctx = new Classpathxmlapplicationcontext ("Spring/app-context.xml", "Spring/app-dao.xml", "spring/app-action.x
ML "); }
}
}
}
}