我刚刚将Spring Boot应用程序(Spring Cloud Task)从1.5升级到2.0.0(Spring Boot),任务/应用程序中的作业运行得很好,但是在作业完成后jar无法关闭。它卡在这里:
2018-11-14 18:08:21.711 INFO 7720 --- [ main] o.s.b.c.l.support.SimpleJobLauncher : Job: [SimpleJob: [name=testJob]] completed with the following parameters: [{-spring.batch.job.names=testJob, run.id=10}] and the following status: [COMPLETED]
2018-11-14 18:08:21.719 DEBUG 7720 --- [ main] o.s.c.t.r.support.SimpleTaskRepository : Updating: TaskExecution with executionId=16 with the following {exitCode=0, endTime=Wed Nov 14 18:08:21 IST 2018, exitMessage='null', errorMessage='null'}
在键盘上按ctrl + c组合键后,HikariCP将关闭:
^C2018-11-14 18:08:25.738 INFO 7720 --- [ Thread-4] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated...
2018-11-14 18:08:25.740 INFO 7720 --- [ Thread-4] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown completed.
我想在完成作业后立即关闭应用程序/ jar。
经过反复试验后,我意识到,当我在应用程序.yml中通过休眠模式删除对二级缓存的使用时,它可以正常工作,即,hikariCP在作业完成后关闭。 这是我的application.yaml:
spring:
application:
name: miq-batch
datasource:
url: jdbc:mysql://localhost:3306/scdf
username: root
password: root
driverClassName: org.mariadb.jdbc.Driver
data:
mongodb:
host: localhost
port: 27017
database: profile
jpa:
properties:
hibernate:
implicit_naming_strategy: org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyHbmImpl
hbm2ddl:
auto: update
cache:
use_second_level_cache: true
region.factory_class: org.hibernate.cache.ehcache.EhCacheRegionFactory
use_query_cache: true
use_collection_cache: true
jackson:
serialization:
FAIL_ON_EMPTY_BEANS: false