diff --git a/src/main/resources/modules/SpringBoot/java/config/ActionConfig.java b/src/main/resources/modules/SpringBoot/java/config/ActionConfig.java index dc7ed949..98ae33c2 100644 --- a/src/main/resources/modules/SpringBoot/java/config/ActionConfig.java +++ b/src/main/resources/modules/SpringBoot/java/config/ActionConfig.java @@ -59,6 +59,7 @@ public class ActionConfig implements BeanDefinitionRegistryPostProcessor { private int registryScreen(String basePackage, BeanDefinitionRegistry beanDefinitionRegistry) { ClassPathBeanDefinitionScanner classPathBeanDefinitionScanner = new ClassPathBeanDefinitionScanner(beanDefinitionRegistry); + classPathBeanDefinitionScanner.resetFilters(false); classPathBeanDefinitionScanner.addIncludeFilter(new AssignableTypeFilter(Screen.class)); classPathBeanDefinitionScanner.setBeanNameGenerator(new BeanNameGenerator() { @Override @@ -74,6 +75,7 @@ public class ActionConfig implements BeanDefinitionRegistryPostProcessor { private int registryControl(String basePackage, BeanDefinitionRegistry beanDefinitionRegistry) { ClassPathBeanDefinitionScanner classPathBeanDefinitionScanner = new ClassPathBeanDefinitionScanner(beanDefinitionRegistry); + classPathBeanDefinitionScanner.resetFilters(false); classPathBeanDefinitionScanner.addIncludeFilter(new AssignableTypeFilter(Control.class)); classPathBeanDefinitionScanner.setBeanNameGenerator(new BeanNameGenerator() { @Override @@ -89,6 +91,7 @@ public class ActionConfig implements BeanDefinitionRegistryPostProcessor { private int registryAjax(String basePackage, BeanDefinitionRegistry beanDefinitionRegistry) { ClassPathBeanDefinitionScanner classPathBeanDefinitionScanner = new ClassPathBeanDefinitionScanner(beanDefinitionRegistry); + classPathBeanDefinitionScanner.resetFilters(false); classPathBeanDefinitionScanner.addIncludeFilter(new TypeFilter() { @Override public boolean match(MetadataReader metadataReader, MetadataReaderFactory metadataReaderFactory) throws IOException { diff --git a/src/main/resources/modules/SpringBoot/java/config/ScheduleConfig.java b/src/main/resources/modules/SpringBoot/java/config/ScheduleConfig.java index af6f90c5..b21bb794 100644 --- a/src/main/resources/modules/SpringBoot/java/config/ScheduleConfig.java +++ b/src/main/resources/modules/SpringBoot/java/config/ScheduleConfig.java @@ -58,7 +58,7 @@ public class ScheduleConfig extends ThreadPoolTaskScheduler implements BeanDefin Matcher matcher = compile.matcher(aPackage); if (matcher.find()) { String basePackage = matcher.group(1); - registryTask(basePackage + ".task", beanDefinitionRegistry); + registryTask(basePackage, beanDefinitionRegistry); } } diff --git a/src/main/resources/modules/SpringBoot/java/frame/schedule/RunSqlTask.java b/src/main/resources/modules/SpringBoot/java/frame/schedule/RunSqlTask.java index 3074e6da..38762eb7 100644 --- a/src/main/resources/modules/SpringBoot/java/frame/schedule/RunSqlTask.java +++ b/src/main/resources/modules/SpringBoot/java/frame/schedule/RunSqlTask.java @@ -1,11 +1,40 @@ package ${basePackage}.frame.schedule; +import org.apache.ibatis.session.SqlSession; +import org.apache.ibatis.session.SqlSessionFactory; +import ${basePackage}.frame.auth.LocalData; +import ${basePackage}.frame.utils.LogUtil; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.SQLException; + public abstract class RunSqlTask extends RunFixRepeatTask { - public abstract String getSql(); + private Connection connection; @Override public void run() { - //exec sql + try { + if (connection == null || connection.isClosed()) { + SqlSessionFactory factory = LocalData.getBean(SqlSessionFactory.class); + SqlSession sqlSession = factory.openSession(true); + connection = sqlSession.getConnection(); + } + } catch (Exception e) { + e.printStackTrace(); + LogUtil.e("schedule: get connection failed!"); + return; + } + try { + PreparedStatement preparedStatement = connection.prepareStatement(getSql()); + preparedStatement.execute(); + preparedStatement.close(); + } catch (SQLException e) { + e.printStackTrace(); + LogUtil.e("RunSqlTask exec failed! SQL:[" + getSql() + "]"); + } } + + public abstract String getSql(); }