1.スクリーンショット
2.DemoService
パッケージcom.github.weiwei02.springcloudtaskdemo。 輸入org.springframework.beans.factory.annotation.Value。 輸入org.springframework.stereotype.Service。 @Service パブリック クラスDemoService { @value(" $ {test.value} " ) プライベート文字列testValueAnno。 公共 のボイドテスト(){ システム。アウト.println(testValueAnno)。 } }
3.SpringCloudTaskDemoApplication
パッケージcom.github.weiwei02.springcloudtaskdemo。 輸入org.springframework.boot.CommandLineRunner。 輸入org.springframework.boot.SpringApplication。 輸入org.springframework.boot.autoconfigure.SpringBootApplication。 輸入javax.annotation.Resource。 @SpringBootApplication パブリック クラスSpringCloudTaskDemoApplicationは{CommandLineRunnerを実装 @Resource プライベートDemoService demoService。 パブリック 静的 ボイドメイン(文字列[]引数)例外{スロー SpringApplication.run(SpringCloudTaskDemoApplication。クラス、引数)を、 } 公共 のボイド実行(文字列...文字列){ 新しいスレッド(){ 公共 ボイドラン(){ しようと{ (のThread.sleepを10000 )。 demoService.test(); } キャッチ(InterruptedExceptionある電子){ e.printStackTrace(); } } } .start(); } }
4.application.yml
春:
アプリケーション:
名:HelloWorldのの
ログ:
level.org.springframework.cloud.task:DEBUGの
テスト:
値:私は中国人です!