gdg
2020-11-05 f17321ffe08c8c44ca1d3cc5f566ee8605ce1c50
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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> 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;
    }
 
}