111
k94314517
2025-07-15 3d5f77b68bf28291c76306b274a230dd726838d2
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
42
43
44
45
46
47
48
package com.doumee.core.utils;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;
 
/**
 * Spring上下文工具
 * @author  dm
 * @since 2025/03/31 16:44
 */
@Component
public class ApplicationContextHelper {
 
    @Autowired
    public ApplicationContext applicationContext;
 
    /**
     * 获取Bean实例
     *
     * @param name 类注册名称
     * @return Object
     */
    public Object getBean(String name) {
        return applicationContext.getBean(name);
    }
 
    /**
     * 获取Bean实例
     *
     * @param clazz Class
     * @return T
     */
    public <T> T getBean(Class<T> clazz){
        return applicationContext.getBean(clazz);
    }
 
    /**
     * 获取Bean实例
     *
     * @param name 类注册名称
     * @param clazz Class
     * @return T
     */
    public <T> T getBean(String name, Class<T> clazz) {
        return applicationContext.getBean(name, clazz);
    }
}