From f1d079f9c0b3d384090477ca54e0548373d62b57 Mon Sep 17 00:00:00 2001
From: zhongrj <646384940@qq.com>
Date: Thu, 16 Jan 2025 11:56:39 +0800
Subject: [PATCH] 配置修改

---
 src/main/java/com/genersoft/iot/vmp/utils/SpringBeanFactory.java |   50 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 50 insertions(+), 0 deletions(-)

diff --git a/src/main/java/com/genersoft/iot/vmp/utils/SpringBeanFactory.java b/src/main/java/com/genersoft/iot/vmp/utils/SpringBeanFactory.java
new file mode 100644
index 0000000..1806524
--- /dev/null
+++ b/src/main/java/com/genersoft/iot/vmp/utils/SpringBeanFactory.java
@@ -0,0 +1,50 @@
+package com.genersoft.iot.vmp.utils;
+
+import org.springframework.beans.BeansException;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
+import org.springframework.stereotype.Component;
+
+/**    
+ * @description:spring bean获取工厂,获取spring中的已初始化的bean
+ * @author: swwheihei
+ * @date:   2019年6月25日 下午4:51:52   
+ * 
+ */
+@Component
+public class SpringBeanFactory implements ApplicationContextAware {
+
+	// Spring应用上下文环境
+    private static ApplicationContext applicationContext;
+    
+    /**
+     * 实现ApplicationContextAware接口的回调方法,设置上下文环境
+     */
+    @Override
+    public void setApplicationContext(ApplicationContext applicationContext)
+            throws BeansException {
+    	SpringBeanFactory.applicationContext = applicationContext;
+    }
+
+    public static ApplicationContext getApplicationContext() {
+        return applicationContext;
+    }
+
+    /**
+     * 获取对象 这里重写了bean方法,起主要作用
+     */
+    public static  <T> T getBean(String beanId) throws BeansException {
+        if (applicationContext == null) {
+            return null;
+        }
+        return (T) applicationContext.getBean(beanId);
+    }
+
+    /**
+     * 获取当前环境
+     */
+    public static String getActiveProfile() {
+        return applicationContext.getEnvironment().getActiveProfiles()[0];
+    }
+
+}

--
Gitblit v1.9.3