ソースを参照

add:通过环境变量控制调度开启v1

tujidelv 3 年 前
コミット
c48c2acc2e

+ 0 - 2
src/main/java/top/lvzhiqiang/App.java

@@ -4,12 +4,10 @@ import org.mybatis.spring.annotation.MapperScan;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.scheduling.annotation.EnableAsync;
-import org.springframework.scheduling.annotation.EnableScheduling;
 
 @MapperScan(basePackages = "top.lvzhiqiang.mapper")
 @SpringBootApplication
 @EnableAsync
-@EnableScheduling
 public class App {
     public static void main(String[] args) {
         SpringApplication.run(App.class, args);

+ 14 - 0
src/main/java/top/lvzhiqiang/config/ScheduleConfig.java

@@ -0,0 +1,14 @@
+package top.lvzhiqiang.config;
+
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.scheduling.annotation.EnableScheduling;
+
+/**
+ * 通过环境变量控制调度开启
+ */
+@Configuration
+@EnableScheduling
+@ConditionalOnProperty(value = "schedule.enable", havingValue = "true", matchIfMissing = true)
+public class ScheduleConfig {
+}

+ 3 - 1
src/main/resources/application-dev.yml

@@ -45,4 +45,6 @@ spring:
       connection-test-query: SELECT 1
 # 日志配置
 logging:
-  config: classpath:env/dev/log4j2-spring.xml
+  config: classpath:env/dev/log4j2-spring.xml
+schedule:
+  enable: false

+ 3 - 1
src/main/resources/application-test.yml

@@ -45,4 +45,6 @@ spring:
       connection-test-query: SELECT 1
 # 日志配置
 logging:
-  config: classpath:env/test/log4j2-spring.xml
+  config: classpath:env/test/log4j2-spring.xml
+schedule:
+  enable: true