在默認(rèn)情況,如果你對(duì) Spring Batch 不進(jìn)行配置的話。
創(chuàng)新互聯(lián)建站網(wǎng)站建設(shè)服務(wù)商,為中小企業(yè)提供網(wǎng)站設(shè)計(jì)、網(wǎng)站制作服務(wù),網(wǎng)站設(shè)計(jì),綿陽(yáng)服務(wù)器托管等一站式綜合服務(wù)型公司,專業(yè)打造企業(yè)形象網(wǎng)站,讓您在眾多競(jìng)爭(zhēng)對(duì)手中脫穎而出創(chuàng)新互聯(lián)建站。
你可以 Check out 到本地后運(yùn)行:
gradlew :service:bootJar
將會(huì)對(duì)項(xiàng)目進(jìn)行編譯,程序?qū)?huì)輸出:
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>
然后你可以運(yùn)行
java -jar service/build/libs/service.jar
你會(huì)發(fā)現(xiàn)沒(méi)有作業(yè)被執(zhí)行
程序輸出如下:
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>
如果你希望有作業(yè)被默認(rèn)執(zhí)行的話,你需要修改你檢出項(xiàng)目的 application.properties 文件
將參數(shù)
spring.batch.job.enabled=false
修改為 true
然后重新編譯然后執(zhí)行,你將會(huì)發(fā)現(xiàn)所有作業(yè)將會(huì)被默認(rèn)執(zhí)行了。
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>
請(qǐng)注意,在這里我們配置了
spring.batch.job.names=cloudClean
所以默認(rèn)將會(huì)執(zhí)行 cloudClean 作業(yè)。
或者你可以執(zhí)行運(yùn)行命令:
java -jar service/build/libs/service.jar --spring.batch.job.enabled=true --spring.batch.job.names=cloudClean
將會(huì)執(zhí)行你指定的作業(yè)。