add
gdg
2020-10-30 9222b2db700cd25e46b67c2a3c05fffd3817cc64
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;
    }
 
}