package com.nanometer.smartlab.util; import org.apache.log4j.Logger; import org.springframework.web.context.ContextLoaderListener; public class SpringUtil { private static Logger logger = Logger.getLogger(SpringUtil.class); @SuppressWarnings("unchecked") public static T getBean(String name, @SuppressWarnings("rawtypes") Class T) { Object bean = ContextLoaderListener.getCurrentWebApplicationContext().getBean(name); if (bean == null) { logger.warn("not found the bean:" + name); return null; } return (T) bean; } }