久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

      <legend id='OC9tl'><style id='OC9tl'><dir id='OC9tl'><q id='OC9tl'></q></dir></style></legend>

          <bdo id='OC9tl'></bdo><ul id='OC9tl'></ul>
      1. <tfoot id='OC9tl'></tfoot>

      2. <i id='OC9tl'><tr id='OC9tl'><dt id='OC9tl'><q id='OC9tl'><span id='OC9tl'><b id='OC9tl'><form id='OC9tl'><ins id='OC9tl'></ins><ul id='OC9tl'></ul><sub id='OC9tl'></sub></form><legend id='OC9tl'></legend><bdo id='OC9tl'><pre id='OC9tl'><center id='OC9tl'></center></pre></bdo></b><th id='OC9tl'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='OC9tl'><tfoot id='OC9tl'></tfoot><dl id='OC9tl'><fieldset id='OC9tl'></fieldset></dl></div>
      3. <small id='OC9tl'></small><noframes id='OC9tl'>

        在 Spring Boot IntegrationTest 上禁用 @Schedule

        Disable @Schedule on Spring Boot IntegrationTest(在 Spring Boot IntegrationTest 上禁用 @Schedule)

          <tfoot id='rKSIc'></tfoot>
            <i id='rKSIc'><tr id='rKSIc'><dt id='rKSIc'><q id='rKSIc'><span id='rKSIc'><b id='rKSIc'><form id='rKSIc'><ins id='rKSIc'></ins><ul id='rKSIc'></ul><sub id='rKSIc'></sub></form><legend id='rKSIc'></legend><bdo id='rKSIc'><pre id='rKSIc'><center id='rKSIc'></center></pre></bdo></b><th id='rKSIc'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='rKSIc'><tfoot id='rKSIc'></tfoot><dl id='rKSIc'><fieldset id='rKSIc'></fieldset></dl></div>
              <tbody id='rKSIc'></tbody>
              • <small id='rKSIc'></small><noframes id='rKSIc'>

                • <bdo id='rKSIc'></bdo><ul id='rKSIc'></ul>

                  <legend id='rKSIc'><style id='rKSIc'><dir id='rKSIc'><q id='rKSIc'></q></dir></style></legend>
                  本文介紹了在 Spring Boot IntegrationTest 上禁用 @Schedule的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  如何在 Spring Boot IntegrationTest 上禁用計劃自動啟動?

                  How can I disable the schedule auto-start on Spring Boot IntegrationTest?

                  謝謝.

                  推薦答案

                  請注意,外部組件可能會自動啟用調度(參見 HystrixStreamAutoConfiguration 和 MetricExportAutoConfiguration 來自 Spring 框架).因此,如果您嘗試在指定 @EnableScheduling@Configuration 類上使用 @ConditionalOnProperty@Profile,那么由于外部組件,無論如何都會啟用調度.

                  Be aware that external components could be enabling scheduling automatically (see HystrixStreamAutoConfiguration and MetricExportAutoConfiguration from the Spring Framework). So if you try and use @ConditionalOnProperty or @Profile on the @Configuration class that specifies @EnableScheduling, then scheduling will be enabled anyway due to external components.

                  有一個 @Configuration 類可以通過 @EnableScheduling 進行調度,然后將你的調度作業放在單獨的類中,每個類都使用 @ConditionalOnProperty 來啟用/禁用包含@Scheduled 任務的類.

                  Have one @Configuration class that enables scheduling via @EnableScheduling, but then have your scheduled jobs in separate classes, each of those using @ConditionalOnProperty to enable/disable the classes that contain the @Scheduled tasks.

                  不要將 @Scheduled@EnableScheduling 放在同一個類中,否則您將遇到外部組件啟用它的問題,因此 @ConditionalOnProperty 被忽略.

                  Don't have the @Scheduled and @EnableScheduling in the same class, or you will have the issue where external components are enabling it anyway, so the @ConditionalOnProperty is ignored.

                  例如:

                  @Configuration
                  @EnableScheduling
                  public class MyApplicationSchedulingConfiguration {
                  }
                  

                  然后在一個單獨的類中

                  @Named
                  @ConditionalOnProperty(value = "scheduling.enabled", havingValue = "true", matchIfMissing = false)
                  public class MyApplicationScheduledTasks {
                  
                    @Scheduled(fixedRate = 60 * 60 * 1000)
                    public void runSomeTaskHourly() {
                      doStuff();
                    }
                  }
                  

                  這個解決方案的問題是每個計劃的作業都需要在它自己的類中,并指定 @ConditionalOnProperty.如果您錯過了該注釋,那么作業將運行.

                  The issue with this solution is that every scheduled job needs to be in it's own class with @ConditionalOnProperty specified. If you miss that annotation, then the job will run.

                  擴展 ThreadPoolTask??Scheduler 并覆蓋 TaskScheduler 方法.在這些方法中,您可以檢查作業是否應該運行.

                  Extend the ThreadPoolTaskScheduler and override the TaskScheduler methods. In these methods you can perform a check to see if the job should run.

                  然后,在您使用@EnableScheduling 的@Configuration 類中,您還創建一個名為taskScheduler 的@Bean,它返回您的自定義線程池任務調度程序.

                  Then, in your @Configuration class where you use @EnableScheduling, you also create a @Bean called taskScheduler which returns your custom thread pool task scheduler).

                  例如:

                  public class ConditionalThreadPoolTaskScheduler extends ThreadPoolTaskScheduler {
                  
                    @Inject
                    private Environment environment;
                  
                    // Override the TaskScheduler methods
                    @Override
                    public ScheduledFuture<?> schedule(Runnable task, Trigger trigger) {
                      if (!canRun()) {
                        return null;
                      }
                      return super.schedule(task, trigger);
                    }
                  
                    @Override
                    public ScheduledFuture<?> schedule(Runnable task, Date startTime) {
                      if (!canRun()) {
                        return null;
                      }
                      return super.schedule(task, startTime);
                    }
                  
                    @Override
                    public ScheduledFuture<?> scheduleAtFixedRate(Runnable task, Date startTime, long period) {
                      if (!canRun()) {
                        return null;
                      }
                      return super.scheduleAtFixedRate(task, startTime, period);
                    }
                  
                    @Override
                    public ScheduledFuture<?> scheduleAtFixedRate(Runnable task, long period) {
                      if (!canRun()) {
                        return null;
                      }
                      return super.scheduleAtFixedRate(task, period);
                    }
                  
                    @Override
                    public ScheduledFuture<?> scheduleWithFixedDelay(Runnable task, Date startTime, long delay) {
                      if (!canRun()) {
                        return null;
                      }
                      return super.scheduleWithFixedDelay(task, startTime, delay);
                    }
                  
                    @Override
                    public ScheduledFuture<?> scheduleWithFixedDelay(Runnable task, long delay) {
                      if (!canRun()) {
                        return null;
                      }
                      return super.scheduleWithFixedDelay(task, delay);
                    }
                  
                    private boolean canRun() {
                      if (environment == null) {
                        return false;
                      }
                  
                      if (!Boolean.valueOf(environment.getProperty("scheduling.enabled"))) {
                        return false;
                      }
                  
                      return true;
                    }
                  }
                  

                  使用我們的自定義調度程序創建 taskScheduler bean 并啟用調度的配置類

                  Configuration class that creates the taskScheduler bean using our custom scheduler, and enables scheduling

                  @Configuration
                  @EnableScheduling
                  public class MyApplicationSchedulingConfiguration {
                  
                    @Bean
                    public TaskScheduler taskScheduler() {
                      return new ConditionalThreadPoolTaskScheduler();
                    }
                  }
                  

                  上面的潛在問題是您已經創建了對內部 Spring 類的依賴,因此如果將來有更改,您必須修復兼容性.

                  The potential issue with the above is that you've created a dependency on an internal Spring class, so if there are changes in the future, you'd have to fix compatibility.

                  這篇關于在 Spring Boot IntegrationTest 上禁用 @Schedule的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  How can I detect integer overflow on 32 bits int?(如何檢測 32 位 int 上的整數溢出?)
                  Local variables before return statements, does it matter?(return 語句之前的局部變量,這有關系嗎?)
                  How to convert Integer to int?(如何將整數轉換為整數?)
                  How do I create an int array with randomly shuffled numbers in a given range(如何在給定范圍內創建一個隨機打亂數字的 int 數組)
                  Inconsistent behavior on java#39;s ==(java的行為不一致==)
                  Why is Java able to store 0xff000000 as an int?(為什么 Java 能夠將 0xff000000 存儲為 int?)
                    <bdo id='4P5Jd'></bdo><ul id='4P5Jd'></ul>

                    <i id='4P5Jd'><tr id='4P5Jd'><dt id='4P5Jd'><q id='4P5Jd'><span id='4P5Jd'><b id='4P5Jd'><form id='4P5Jd'><ins id='4P5Jd'></ins><ul id='4P5Jd'></ul><sub id='4P5Jd'></sub></form><legend id='4P5Jd'></legend><bdo id='4P5Jd'><pre id='4P5Jd'><center id='4P5Jd'></center></pre></bdo></b><th id='4P5Jd'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='4P5Jd'><tfoot id='4P5Jd'></tfoot><dl id='4P5Jd'><fieldset id='4P5Jd'></fieldset></dl></div>

                        • <small id='4P5Jd'></small><noframes id='4P5Jd'>

                        • <legend id='4P5Jd'><style id='4P5Jd'><dir id='4P5Jd'><q id='4P5Jd'></q></dir></style></legend>
                            <tbody id='4P5Jd'></tbody>
                            <tfoot id='4P5Jd'></tfoot>
                          1. 主站蜘蛛池模板: 日本不卡免费新一二三区 | 亚洲视频欧美视频 | www.一区二区三区 | 中文字幕亚洲一区二区三区 | 亚洲精品一二三 | 色啪网 | 91在线视频播放 | 亚洲国产一区二区视频 | 午夜精品久久久久久久星辰影院 | 精品一区二区三区四区 | 国产美女精品 | 一区二区三区av | 精品免费视频 | 一级做a爰片久久毛片 | 欧美精品导航 | 日韩精品一区在线观看 | 欧美日韩视频在线播放 | 欧美国产亚洲一区二区 | 久久久精品一区二区三区 | 91精品国产高清久久久久久久久 | 中文字幕视频在线看 | www.v888av.com| 国产精品久久久久aaaa | 99re66在线观看精品热 | 在线婷婷| 亚洲精品无 | 午夜不卡福利视频 | 久久大陆 | 欧美成年人网站 | 亚洲欧美日韩成人在线 | 免费三级黄 | 午夜视频在线 | 精品欧美一区二区久久久伦 | 五月天天色 | 欧美精品在线一区二区三区 | 欧美精品久久久 | 亚洲一区影院 | 亚洲欧美日本在线 | 精品国产欧美一区二区三区成人 | 久久婷婷麻豆国产91天堂 | 91国内精品 |