1.报错信息
org.springframework.context.ApplicationContextException: Failed to start bean 'quartzScheduler'; nested exception is org.springframework.scheduling.SchedulingException: Could not start Quartz Scheduler; nested exception is org.quartz.SchedulerConfigException: Failure occured during job recovery. [See nested exception: org.quartz.impl.jdbcjobstore.LockException: Failure obtaining db row lock: 第 1 行: 只有 DECLARE CURSOR 才允许使用 FOR UPDATE 子句。 [See nested exception: com.microsoft.sqlserver.jdbc.SQLServerException: 第 1 行: 只有 DECLARE CURSOR 才允许使用 FOR UPDATE 子句。]]
出现这个错误的时候,我一直以为是Quartz的配置有问题,去掉spring.quartz.job-store-type= jdbc就不报错,加上就报错。出现这个错误是sqlserver的配置的问题。
原因:quartz用到了游标,而sqlserver默认是不打开游标的,要使用游标必须使用SelectMethod=Cursor才打开游标,否则就会报错
spring:
datasource:
driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver
url: jdbc:sqlserver://localhost:1433;DatabaseName=kaoqin
username: sa
password: 123456
加上SelectMethod=cursor;就可以了
spring:
datasource:
driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver
url: jdbc:sqlserver://localhost:1433;SelectMethod=cursor;DatabaseName=kaoqin
username: sa
password: 123456