Commit cc156f6ea3fea92307cc9299df9512d705bd2f8c
1 parent
f9adedda
bean工具类替换为hutool的
Showing
2 changed files
with
2 additions
and
85 deletions
src/main/java/cn/iocoder/dashboard/framework/tracer/core/util/TracerUtils.java
| 1 | 1 | package cn.iocoder.dashboard.framework.tracer.core.util; |
| 2 | 2 | |
| 3 | 3 | import cn.hutool.core.util.StrUtil; |
| 4 | +import cn.hutool.extra.spring.SpringUtil; | |
| 4 | 5 | import cn.iocoder.dashboard.framework.tracer.core.ITrace; |
| 5 | -import cn.iocoder.dashboard.util.sping.SpringBeanUtil; | |
| 6 | 6 | import org.apache.skywalking.apm.toolkit.trace.TraceContext; |
| 7 | 7 | |
| 8 | 8 | import java.util.UUID; |
| ... | ... | @@ -61,7 +61,7 @@ public class TracerUtils { |
| 61 | 61 | * @return ITrace |
| 62 | 62 | */ |
| 63 | 63 | private static ITrace getTracer() { |
| 64 | - return SpringBeanUtil.getBean(ITrace.class); | |
| 64 | + return SpringUtil.getBean(ITrace.class); | |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | /** | ... | ... |
src/main/java/cn/iocoder/dashboard/util/sping/SpringBeanUtil.java deleted
| 1 | -package cn.iocoder.dashboard.util.sping; | |
| 2 | - | |
| 3 | -import org.springframework.beans.BeansException; | |
| 4 | - | |
| 5 | -import org.springframework.beans.factory.NoSuchBeanDefinitionException; | |
| 6 | - | |
| 7 | -import org.springframework.context.ApplicationContext; | |
| 8 | - | |
| 9 | -import org.springframework.context.ApplicationContextAware; | |
| 10 | - | |
| 11 | -import org.springframework.stereotype.Component; | |
| 12 | - | |
| 13 | - | |
| 14 | -@Component | |
| 15 | -public class SpringBeanUtil implements ApplicationContextAware { | |
| 16 | - | |
| 17 | - /** | |
| 18 | - * Spring context | |
| 19 | - */ | |
| 20 | - private static ApplicationContext applicationContext = null; | |
| 21 | - | |
| 22 | - public void setApplicationContext(ApplicationContext context) throws BeansException { | |
| 23 | - if (applicationContext == null) { | |
| 24 | - applicationContext = context; | |
| 25 | - } | |
| 26 | - } | |
| 27 | - | |
| 28 | - public static ApplicationContext getApplicationContext() { | |
| 29 | - return applicationContext; | |
| 30 | - } | |
| 31 | - | |
| 32 | - public static void setAppCtx(ApplicationContext webAppCtx) { | |
| 33 | - if (webAppCtx != null) { | |
| 34 | - applicationContext = webAppCtx; | |
| 35 | - } | |
| 36 | - } | |
| 37 | - | |
| 38 | - | |
| 39 | - /** | |
| 40 | - * 拿到ApplicationContext对象实例后就可以手动获取Bean的注入实例对象 | |
| 41 | - */ | |
| 42 | - public static <T> T getBean(Class<T> clazz) { | |
| 43 | - return getApplicationContext() == null ? null : getApplicationContext().getBean(clazz); | |
| 44 | - } | |
| 45 | - | |
| 46 | - | |
| 47 | - public static <T> T getBean(String name, Class<T> clazz) throws ClassNotFoundException { | |
| 48 | - return getApplicationContext() == null ? null : getApplicationContext() .getBean(name, clazz); | |
| 49 | - } | |
| 50 | - | |
| 51 | - | |
| 52 | - public static final Object getBean(String beanName) { | |
| 53 | - return getApplicationContext() == null ? null : getApplicationContext() .getBean(beanName); | |
| 54 | - } | |
| 55 | - | |
| 56 | - | |
| 57 | - public static final Object getBean(String beanName, String className) throws ClassNotFoundException { | |
| 58 | - Class<?> clz = Class.forName(className); | |
| 59 | - return getApplicationContext() == null ? null : getApplicationContext() .getBean(beanName, clz.getClass()); | |
| 60 | - | |
| 61 | - } | |
| 62 | - | |
| 63 | - | |
| 64 | - public static boolean containsBean(String name) { | |
| 65 | - return getApplicationContext() == null ? null : getApplicationContext() .containsBean(name); | |
| 66 | - } | |
| 67 | - | |
| 68 | - | |
| 69 | - public static boolean isSingleton(String name) throws NoSuchBeanDefinitionException { | |
| 70 | - return getApplicationContext() == null ? null : getApplicationContext() .isSingleton(name); | |
| 71 | - } | |
| 72 | - | |
| 73 | - | |
| 74 | - public static Class<?> getType(String name) throws NoSuchBeanDefinitionException { | |
| 75 | - return getApplicationContext() == null ? null : getApplicationContext() .getType(name); | |
| 76 | - } | |
| 77 | - | |
| 78 | - | |
| 79 | - public static String[] getAliases(String name) throws NoSuchBeanDefinitionException { | |
| 80 | - return getApplicationContext() == null ? null : getApplicationContext() .getAliases(name); | |
| 81 | - } | |
| 82 | - | |
| 83 | -} | |
| 84 | 0 | \ No newline at end of file |