From cc156f6ea3fea92307cc9299df9512d705bd2f8c Mon Sep 17 00:00:00 2001 From: dark <189192663@qq.com> Date: Tue, 9 Mar 2021 20:23:37 +0800 Subject: [PATCH] =?UTF-8?q?bean=E5=B7=A5=E5=85=B7=E7=B1=BB=E6=9B=BF?= =?UTF-8?q?=E6=8D=A2=E4=B8=BAhutool=E7=9A=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tracer/core/util/TracerUtils.java | 4 +- .../dashboard/util/sping/SpringBeanUtil.java | 83 ------------------- 2 files changed, 2 insertions(+), 85 deletions(-) delete mode 100644 src/main/java/cn/iocoder/dashboard/util/sping/SpringBeanUtil.java diff --git a/src/main/java/cn/iocoder/dashboard/framework/tracer/core/util/TracerUtils.java b/src/main/java/cn/iocoder/dashboard/framework/tracer/core/util/TracerUtils.java index dfcb349a3..033216260 100644 --- a/src/main/java/cn/iocoder/dashboard/framework/tracer/core/util/TracerUtils.java +++ b/src/main/java/cn/iocoder/dashboard/framework/tracer/core/util/TracerUtils.java @@ -1,8 +1,8 @@ package cn.iocoder.dashboard.framework.tracer.core.util; import cn.hutool.core.util.StrUtil; +import cn.hutool.extra.spring.SpringUtil; import cn.iocoder.dashboard.framework.tracer.core.ITrace; -import cn.iocoder.dashboard.util.sping.SpringBeanUtil; import org.apache.skywalking.apm.toolkit.trace.TraceContext; import java.util.UUID; @@ -61,7 +61,7 @@ public class TracerUtils { * @return ITrace */ private static ITrace getTracer() { - return SpringBeanUtil.getBean(ITrace.class); + return SpringUtil.getBean(ITrace.class); } /** diff --git a/src/main/java/cn/iocoder/dashboard/util/sping/SpringBeanUtil.java b/src/main/java/cn/iocoder/dashboard/util/sping/SpringBeanUtil.java deleted file mode 100644 index c2fd5c487..000000000 --- a/src/main/java/cn/iocoder/dashboard/util/sping/SpringBeanUtil.java +++ /dev/null @@ -1,83 +0,0 @@ -package cn.iocoder.dashboard.util.sping; - -import org.springframework.beans.BeansException; - -import org.springframework.beans.factory.NoSuchBeanDefinitionException; - -import org.springframework.context.ApplicationContext; - -import org.springframework.context.ApplicationContextAware; - -import org.springframework.stereotype.Component; - - -@Component -public class SpringBeanUtil implements ApplicationContextAware { - - /** - * Spring context - */ - private static ApplicationContext applicationContext = null; - - public void setApplicationContext(ApplicationContext context) throws BeansException { - if (applicationContext == null) { - applicationContext = context; - } - } - - public static ApplicationContext getApplicationContext() { - return applicationContext; - } - - public static void setAppCtx(ApplicationContext webAppCtx) { - if (webAppCtx != null) { - applicationContext = webAppCtx; - } - } - - - /** - * 拿到ApplicationContext对象实例后就可以手动获取Bean的注入实例对象 - */ - public static T getBean(Class clazz) { - return getApplicationContext() == null ? null : getApplicationContext().getBean(clazz); - } - - - public static T getBean(String name, Class clazz) throws ClassNotFoundException { - return getApplicationContext() == null ? null : getApplicationContext() .getBean(name, clazz); - } - - - public static final Object getBean(String beanName) { - return getApplicationContext() == null ? null : getApplicationContext() .getBean(beanName); - } - - - public static final Object getBean(String beanName, String className) throws ClassNotFoundException { - Class clz = Class.forName(className); - return getApplicationContext() == null ? null : getApplicationContext() .getBean(beanName, clz.getClass()); - - } - - - public static boolean containsBean(String name) { - return getApplicationContext() == null ? null : getApplicationContext() .containsBean(name); - } - - - public static boolean isSingleton(String name) throws NoSuchBeanDefinitionException { - return getApplicationContext() == null ? null : getApplicationContext() .isSingleton(name); - } - - - public static Class getType(String name) throws NoSuchBeanDefinitionException { - return getApplicationContext() == null ? null : getApplicationContext() .getType(name); - } - - - public static String[] getAliases(String name) throws NoSuchBeanDefinitionException { - return getApplicationContext() == null ? null : getApplicationContext() .getAliases(name); - } - -} \ No newline at end of file