From 44b1fe9f7e766a2f30aa42add10ab3398fecc333 Mon Sep 17 00:00:00 2001 From: wangbing <1919101440@qq.com> Date: Mon, 30 Dec 2019 23:41:19 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Former-commit-id: 3ae467fbfaf0d999adbeadba3c061f82187fc719 --- .../java/config/ScheduleConfig.java | 44 +++++++++++-------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/src/main/resources/modules/SpringBoot/java/config/ScheduleConfig.java b/src/main/resources/modules/SpringBoot/java/config/ScheduleConfig.java index 87d6d28a..a43d91a4 100644 --- a/src/main/resources/modules/SpringBoot/java/config/ScheduleConfig.java +++ b/src/main/resources/modules/SpringBoot/java/config/ScheduleConfig.java @@ -1,23 +1,23 @@ package ${basePackage}.config; -import org.springframework.beans.BeansException; -import org.springframework.beans.factory.config.BeanDefinition; -import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; -import org.springframework.beans.factory.support.BeanDefinitionRegistry; -import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor; -import org.springframework.beans.factory.support.BeanNameGenerator; -import org.springframework.context.annotation.ClassPathBeanDefinitionScanner; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Profile; -import org.springframework.core.type.filter.AssignableTypeFilter; -import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; -import org.springframework.stereotype.Component; -import ${basePackage}.frame.schedule.RunTask; -import ${basePackage}.frame.utils.LogUtil; + import org.springframework.beans.BeansException; + import org.springframework.beans.factory.config.BeanDefinition; + import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; + import org.springframework.beans.factory.support.BeanDefinitionRegistry; + import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor; + import org.springframework.beans.factory.support.BeanNameGenerator; + import org.springframework.context.annotation.ClassPathBeanDefinitionScanner; + import org.springframework.context.annotation.Configuration; + import org.springframework.context.annotation.Profile; + import org.springframework.core.type.filter.AssignableTypeFilter; + import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; + import org.springframework.stereotype.Component; + import ${basePackage}.frame.schedule.RunTask; + import ${basePackage}.frame.utils.LogUtil; -import java.util.HashMap; -import java.util.Map; -import java.util.concurrent.ScheduledFuture; + import java.util.HashMap; + import java.util.Map; + import java.util.concurrent.ScheduledFuture; /** * 计划调度配置,可以指定环境生效,根据实际情况是否需要开启 @@ -40,7 +40,7 @@ public class ScheduleConfig extends ThreadPoolTaskScheduler implements BeanDefin } public boolean createOrRepeat(RunTask task) { - if (futureMap.containsKey(task.taskId())){ + if (futureMap.containsKey(task.taskId())) { ScheduledFuture scheduledFuture = futureMap.get(task.taskId()); scheduledFuture.cancel(false); } @@ -51,7 +51,13 @@ public class ScheduleConfig extends ThreadPoolTaskScheduler implements BeanDefin @Override public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry beanDefinitionRegistry) throws BeansException { - registryTask("${basePackage}.task", beanDefinitionRegistry); + String aPackage = this.getClass().getPackage().getName(); + Pattern compile = Pattern.compile("(.*)\\.config"); + Matcher matcher = compile.matcher(aPackage); + if (matcher.find()) { + String basePackage = matcher.group(1); + registryTask(basePackage + ".task", beanDefinitionRegistry); + } } @Override