Bläddra i källkod

spring工具类移至common

RuoYi 6 år sedan
förälder
incheckning
25d7c2c1f7

+ 1 - 1
ruoyi-framework/src/main/java/com/ruoyi/framework/util/SpringUtils.java → ruoyi-common/src/main/java/com/ruoyi/common/utils/spring/SpringUtils.java

@@ -1,4 +1,4 @@
-package com.ruoyi.framework.util;
+package com.ruoyi.common.utils.spring;
 
 import org.springframework.beans.BeansException;
 import org.springframework.beans.factory.NoSuchBeanDefinitionException;

+ 1 - 1
ruoyi-framework/src/main/java/com/ruoyi/framework/manager/AsyncManager.java

@@ -4,7 +4,7 @@ import java.util.TimerTask;
 import java.util.concurrent.ScheduledExecutorService;
 import java.util.concurrent.TimeUnit;
 import com.ruoyi.common.utils.Threads;
-import com.ruoyi.framework.util.SpringUtils;
+import com.ruoyi.common.utils.spring.SpringUtils;
 
 /**
  * 异步任务管理器

+ 1 - 1
ruoyi-framework/src/main/java/com/ruoyi/framework/manager/factory/AsyncFactory.java

@@ -5,11 +5,11 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import com.ruoyi.common.constant.Constants;
 import com.ruoyi.common.utils.AddressUtils;
+import com.ruoyi.common.utils.spring.SpringUtils;
 import com.ruoyi.framework.shiro.session.OnlineSession;
 import com.ruoyi.framework.util.LogUtils;
 import com.ruoyi.framework.util.ServletUtils;
 import com.ruoyi.framework.util.ShiroUtils;
-import com.ruoyi.framework.util.SpringUtils;
 import com.ruoyi.system.domain.SysLogininfor;
 import com.ruoyi.system.domain.SysOperLog;
 import com.ruoyi.system.domain.SysUserOnline;

+ 1 - 1
ruoyi-framework/src/main/java/com/ruoyi/framework/shiro/web/session/OnlineWebSessionManager.java

@@ -14,8 +14,8 @@ import org.apache.shiro.web.session.mgt.DefaultWebSessionManager;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import com.ruoyi.common.constant.ShiroConstants;
+import com.ruoyi.common.utils.spring.SpringUtils;
 import com.ruoyi.framework.shiro.session.OnlineSession;
-import com.ruoyi.framework.util.SpringUtils;
 import com.ruoyi.system.domain.SysUserOnline;
 import com.ruoyi.system.service.ISysUserOnlineService;
 

+ 1 - 0
ruoyi-framework/src/main/java/com/ruoyi/framework/util/MessageUtils.java

@@ -1,6 +1,7 @@
 package com.ruoyi.framework.util;
 
 import org.springframework.context.MessageSource;
+import com.ruoyi.common.utils.spring.SpringUtils;
 
 /**
  * 获取i18n资源文件

+ 3 - 2
ruoyi-quartz/src/main/java/com/ruoyi/quartz/util/ScheduleJob.java

@@ -13,6 +13,7 @@ import com.ruoyi.common.constant.Constants;
 import com.ruoyi.common.constant.ScheduleConstants;
 import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.common.utils.bean.BeanUtils;
+import com.ruoyi.common.utils.spring.SpringUtils;
 import com.ruoyi.quartz.domain.SysJob;
 import com.ruoyi.quartz.domain.SysJobLog;
 import com.ruoyi.quartz.service.ISysJobLogService;
@@ -28,9 +29,9 @@ public class ScheduleJob extends QuartzJobBean
 {
     private static final Logger log = LoggerFactory.getLogger(ScheduleJob.class);
 
-    private ThreadPoolTaskExecutor executor = (ThreadPoolTaskExecutor) SpringContextUtil.getBean("publicThreadPool");
+    private ThreadPoolTaskExecutor executor = SpringUtils.getBean("threadPoolTaskExecutor");
 
-    private final static ISysJobLogService jobLogService = (ISysJobLogService) SpringContextUtil.getBean("sysJobLogServiceImpl");
+    private final static ISysJobLogService jobLogService = SpringUtils.getBean(ISysJobLogService.class);
 
     @Override
     protected void executeInternal(JobExecutionContext context) throws JobExecutionException

+ 2 - 1
ruoyi-quartz/src/main/java/com/ruoyi/quartz/util/ScheduleRunnable.java

@@ -5,6 +5,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.util.ReflectionUtils;
 import com.ruoyi.common.utils.StringUtils;
+import com.ruoyi.common.utils.spring.SpringUtils;
 
 /**
  * 执行定时任务
@@ -23,7 +24,7 @@ public class ScheduleRunnable implements Runnable
     public ScheduleRunnable(String beanName, String methodName, String params)
             throws NoSuchMethodException, SecurityException
     {
-        this.target = SpringContextUtil.getBean(beanName);
+        this.target = SpringUtils.getBean(beanName);
         this.params = params;
 
         if (StringUtils.isNotEmpty(params))

+ 0 - 49
ruoyi-quartz/src/main/java/com/ruoyi/quartz/util/SpringContextUtil.java

@@ -1,49 +0,0 @@
-package com.ruoyi.quartz.util;
-
-import org.springframework.beans.BeansException;
-import org.springframework.context.ApplicationContext;
-import org.springframework.context.ApplicationContextAware;
-import org.springframework.stereotype.Service;
-
-/**
- * spring管理环境中获取bean
- * 
- * @author yangzz
- */
-@Service("springContextUtil")
-public class SpringContextUtil implements ApplicationContextAware
-{
-    // Spring应用上下文环境
-    private static ApplicationContext applicationContext;
-
-    /**
-     * 实现ApplicationContextAware接口的回调方法,设置上下文环境
-     * 
-     * @param applicationContext
-     */
-    @Override
-    public void setApplicationContext(ApplicationContext applicationContext)
-    {
-        SpringContextUtil.applicationContext = applicationContext;
-    }
-
-    /**
-     * @return ApplicationContext
-     */
-    public static ApplicationContext getApplicationContext()
-    {
-        return applicationContext;
-    }
-
-    /**
-     * 获取对象
-     * 
-     * @param name
-     * @return Object
-     * @throws BeansException
-     */
-    public static Object getBean(String name) throws BeansException
-    {
-        return applicationContext.getBean(name);
-    }
-}