kongzy
2024-07-01 47a751cb301d05276ae5d75145d57b2d090fe4e1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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;
    }
 
 
}