springboot:非ウェブ開始

必要性は、いくつかのスケジュールされたタスクを実行するには、しかし、Webコンテナの中に実行する必要はありません。コードレッドを参照してください。

輸入java.util.concurrent.ThreadPoolExecutor; 

輸入org.springframework.boot.WebApplicationType。
輸入org.springframework.boot.autoconfigure.SpringBootApplication。
輸入org.springframework.boot.builder.SpringApplicationBuilder。
輸入org.springframework.cache.annotation.EnableCaching。
輸入org.springframework.context.annotation.Bean;
輸入org.springframework.context.annotation.ComponentScan;
輸入org.springframework.core.task.AsyncTaskExecutor;
輸入org.springframework.scheduling.annotation.EnableAsync;
輸入org.springframework.scheduling.annotation.EnableScheduling。
輸入org.springframework.scheduling.concurrent.ThreadPoolTask​​Executor;
輸入org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession。

@SpringBootApplication 
@EnableCaching 
@EnableRedisHttpSession 
@EnableAsync 
@EnableScheduling パブリッククラスJspxScheduleApplication { 公共静的ボイドメイン(文字列[]引数){
   新しいSpringApplicationBuilder(JspxScheduleApplication.class ).web(WebApplicationType.NONE).RUN(引数)。
 

      
  } 

  @Bean 
  公共AsyncTaskExecutor asyncTaskExecutor(){ 
    ThreadPoolTask​​Executorキュータ = 新しいThreadPoolTask​​Executor()。
    executor.setThreadNamePrefix( "jspt-schedule-" ); 
    executor.setMaxPoolSize( 30 )。
    executor.setCorePoolSize( 10 )。
    executor.setQueueCapacity( 0 )。
    executor.setRejectedExecutionHandler(新しいThreadPoolExecutor.AbortPolicy());
    リターンキュータ。
  } 

}

WebApplicationTypeは、3つの値があります。

  • NONE - アプリケーションがWebアプリケーションとして実行すべきではない、あなたは、内蔵Webサーバーを起動するべきではありません。
  • REACTIVE - アプリケーションが応答のWebアプリケーションとして実行する必要があり、および内蔵Webサーバに対応して起動する必要があります。
  • SERVLET - アプリケーションは、サーブレットベースのWebアプリケーションとして実行する必要があり、および組み込みサーブレットWebサーバーを開始しなければなりません。

おすすめ

転載: www.cnblogs.com/huiy/p/11834828.html