WangHan
2024-09-12 d5855a4926926698b740bc6c7ba489de47adb68b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package tech.powerjob.server.common.utils;
 
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
 
/**
 * Spring ApplicationContext 工具类
 *
 * @author tjq
 * @since 2020/4/7
 */
@Component
public class SpringUtils implements ApplicationContextAware {
 
    private static ApplicationContext context;
 
    public static <T> T getBean(Class<T> clz) {
        return context.getBean(clz);
    }
 
    public static Object getBean(String beanName) {
        return context.getBean(beanName);
    }
 
    @Override
    public void setApplicationContext(ApplicationContext ctx) throws BeansException {
        context = ctx;
    }
}