您好,登錄后才能下訂單哦!
在默認情況,如果你對 Spring Batch 不進行配置的話。
你可以 Check out 到本地后運行:
gradlew :service:bootJar
將會對項目進行編譯,程序將會輸出:
C:\WorkDir\Repository\Spring\cwiki-us-spring-guides\cwiki-us-spring-batch-examples>gradlew :service:bootJar > Configure project : You are using one or more deprecated Asciidoctor Gradle plugin features. To help with migration run with --warning-mode=all. Repository https://jcenter.bintray.com/ replaced by https://maven.ossez.com/repository/internal. BUILD SUCCESSFUL in 10s 6 actionable tasks: 2 executed, 4 up-to-date C:\WorkDir\Repository\Spring\cwiki-us-spring-guides\cwiki-us-spring-batch-examples>
然后你可以運行
java -jar service/build/libs/service.jar
你會發現沒有作業被執行
程序輸出如下:
C:\WorkDir\Repository\Spring\cwiki-us-spring-guides\cwiki-us-spring-batch-examples>java -jar service/build/libs/service.jar . ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v2.1.4.RELEASE) 2020-02-18 15:32:38.016 INFO 28560 --- [ main] com.ossez.batch.service.Application : Starting Application on USWTWNB47141 with PID 28560 (C:\WorkDir\Repository\Spring\cwiki-us-spring-guides\cwiki-us-spring-batch-exam ples\service\build\libs\service.jar started by yhu in C:\WorkDir\Repository\Spring\cwiki-us-spring-guides\cwiki-us-spring-batch-examples) 2020-02-18 15:32:38.023 INFO 28560 --- [ main] com.ossez.batch.service.Application : No active profile set, falling back to default profiles: default 2020-02-18 15:32:40.344 INFO 28560 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting... 2020-02-18 15:32:40.353 WARN 28560 --- [ main] com.zaxxer.hikari.util.DriverDataSource : Registered driver with driverClassName=org.hsqldb.jdbcDriver was not found, trying direct instantiation. 2020-02-18 15:32:40.854 INFO 28560 --- [ main] com.zaxxer.hikari.pool.PoolBase : HikariPool-1 - Driver does not support get/set network timeout for connections. (feature not supported) 2020-02-18 15:32:40.866 INFO 28560 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed. 2020-02-18 15:32:42.711 INFO 28560 --- [ main] o.s.b.c.r.s.JobRepositoryFactoryBean : No database type set, using meta data indicating: HSQL 2020-02-18 15:32:43.137 INFO 28560 --- [ main] o.s.b.c.l.support.SimpleJobLauncher : No TaskExecutor has been set, defaulting to synchronous executor. 2020-02-18 15:32:44.502 INFO 28560 --- [ main] com.ossez.batch.service.Application : Started Application in 7.373 seconds (JVM running for 8.576) 2020-02-18 15:32:44.529 INFO 28560 --- [ Thread-2] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated... 2020-02-18 15:32:44.537 INFO 28560 --- [ Thread-2] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown completed. C:\WorkDir\Repository\Spring\cwiki-us-spring-guides\cwiki-us-spring-batch-examples>
如果你希望有作業被默認執行的話,你需要修改你檢出項目的 application.properties 文件
將參數
spring.batch.job.enabled=false
修改為 true
然后重新編譯然后執行,你將會發現所有作業將會被默認執行了。
C:\WorkDir\Repository\Spring\cwiki-us-spring-guides\cwiki-us-spring-batch-examples>java -jar service/build/libs/service.jar . ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v2.1.4.RELEASE) 2020-02-18 15:36:29.621 INFO 47168 --- [ main] com.ossez.batch.service.Application : Starting Application on USWTWNB47141 with PID 47168 (C:\WorkDir\Repository\Spring\cwiki-us-spring-guides\cwiki-us-spring-batch-exam ples\service\build\libs\service.jar started by yhu in C:\WorkDir\Repository\Spring\cwiki-us-spring-guides\cwiki-us-spring-batch-examples) 2020-02-18 15:36:29.625 INFO 47168 --- [ main] com.ossez.batch.service.Application : No active profile set, falling back to default profiles: default 2020-02-18 15:36:31.611 INFO 47168 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting... 2020-02-18 15:36:31.620 WARN 47168 --- [ main] com.zaxxer.hikari.util.DriverDataSource : Registered driver with driverClassName=org.hsqldb.jdbcDriver was not found, trying direct instantiation. 2020-02-18 15:36:31.978 INFO 47168 --- [ main] com.zaxxer.hikari.pool.PoolBase : HikariPool-1 - Driver does not support get/set network timeout for connections. (feature not supported) 2020-02-18 15:36:31.984 INFO 47168 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed. 2020-02-18 15:36:33.087 INFO 47168 --- [ main] o.s.b.c.r.s.JobRepositoryFactoryBean : No database type set, using meta data indicating: HSQL 2020-02-18 15:36:33.493 INFO 47168 --- [ main] o.s.b.c.l.support.SimpleJobLauncher : No TaskExecutor has been set, defaulting to synchronous executor. 2020-02-18 15:36:34.706 INFO 47168 --- [ main] com.ossez.batch.service.Application : Started Application in 5.952 seconds (JVM running for 7.127) 2020-02-18 15:36:34.709 INFO 47168 --- [ main] o.s.b.a.b.JobLauncherCommandLineRunner : Running default command line with: [] 2020-02-18 15:36:34.851 INFO 47168 --- [ main] o.s.b.c.l.support.SimpleJobLauncher : Job: [FlowJob: [name=cloudClean]] launched with the following parameters: [{run.id=1}] 2020-02-18 15:36:34.884 INFO 47168 --- [ main] o.s.batch.core.job.SimpleStepHandler : Executing step: [readFilesStep] 2020-02-18 15:36:34.957 INFO 47168 --- [ main] c.o.batch.service.tasklet.FileTasklet : >>++>1582058194905 2020-02-18 15:36:34.974 INFO 47168 --- [ main] o.s.batch.core.job.SimpleStepHandler : Executing step: [deleteFilesStep] 2020-02-18 15:36:34.977 INFO 47168 --- [ main] c.o.batch.service.tasklet.FileTasklet : >>++>1582058194977 2020-02-18 15:36:34.987 INFO 47168 --- [ main] .o.b.s.JobCompletionNotificationListener : !!! JOB FINISHED! Time to verify the results 2020-02-18 15:36:34.990 INFO 47168 --- [ main] o.s.b.c.l.support.SimpleJobLauncher : Job: [FlowJob: [name=cloudClean]] completed with the following parameters: [{run.id=1}] and the following status: [COMPLETED] 2020-02-18 15:36:35.023 INFO 47168 --- [ Thread-2] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated... 2020-02-18 15:36:35.030 INFO 47168 --- [ Thread-2] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown completed. C:\WorkDir\Repository\Spring\cwiki-us-spring-guides\cwiki-us-spring-batch-examples>
請注意,在這里我們配置了
spring.batch.job.names=cloudClean
所以默認將會執行 cloudClean 作業。
或者你可以執行運行命令:
java -jar service/build/libs/service.jar --spring.batch.job.enabled=true --spring.batch.job.names=cloudClean
將會執行你指定的作業。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。