月球大数据地理空间分析展示平台-【后端】-月球后台服务
1
13693261870
2024-11-13 024e90554d19c2342f27a26f91bbea378f84da82
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
32
33
34
35
36
37
38
39
40
41
package com.moon.server.helper;
 
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
 
@Component
@SuppressWarnings("ALL")
public class SpringContextHelper implements ApplicationContextAware {
    private static ApplicationContext context = null;
 
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        context = applicationContext;
    }
 
    public static <T> T getBean(String name) {
        return (T) context.getBean(name);
    }
 
    public static <T> T getBean(Class<T> clazz) {
        return context.getBean(clazz);
    }
 
    public static boolean containsBean(String name) {
        return context.containsBean(name);
    }
 
    public static Class<?> getType(String name) {
        return context.getType(name);
    }
 
    public static ApplicationContext getContext() {
        return context;
    }
 
    public static String getActiveProfile() {
        return context.getEnvironment().getActiveProfiles()[0];
    }
}