如何不配置SpringBatch在默认状态中执行任务?-创新互联
在默认情况,如果你对 Spring Batch 不进行配置的话。
创新互联公司成立于2013年,是专业互联网技术服务公司,拥有项目成都网站制作、成都网站设计网站策划,项目实施与项目整合能力。我们以让每一个梦想脱颖而出为使命,1280元丽江做网站,已为上家服务,为丽江各地企业和个人服务,联系电话:13518219792你可以 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
将会执行你指定的作业。
另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。
网页题目:如何不配置SpringBatch在默认状态中执行任务?-创新互联
本文来源:http://hbruida.cn/article/cdeesc.html