将石英添加到项目中断 jdbc 数据源

Adding quartz to project breaks jdbc dataSource

I've already found out what was the problem, but decided to post it here, in case anyone else is banging head against the same wall.

我已经将最新版本的 quartz scheduler 添加到我的项目中:

<dependency>
   <groupId>org.quartz-scheduler</groupId>
   <artifactId>quartz</artifactId>
   <version>2.2.1</version>
</dependency>

突然测试开始下降:

org.springframework.jdbc.UncategorizedSQLException: PreparedStatementCallback; uncategorized SQLException for SQL [ my sql ]; SQL state [null]; error code [0]; An SQLException was provoked by the following failure: java.lang.InterruptedException; nested exception is java.sql.SQLException: An SQLException was provoked by the following failure: java.lang.InterruptedException  

更奇怪的是,当我将 quartz 依赖项移动到另一个模块时,它们开始失败并出现不同的异常:

Could not get JDBC Connection; nested exception is java.sql.SQLException: com.mchange.v2.c3p0.ComboPooledDataSource[ identityToken -> z8kfsx9b1qeyobp10iytmq|796c39ad, dataSourceName -> z8kfsx9b1qeyobp10iytmq|796c39ad ] has been closed() -- you can no longer use it.

所以,Spring 关闭了我的 ComboPooledDataSource,但为什么呢?

删除 quartz 或将其版本更改为 1。8.x 有帮助。即使没有实例化任何石英对象也会发生异常。

自版本 2.x 起,Quartz 使用 c3p0 jdbc 池作为分布式作业存储,我的项目也使用 c3p0,但较新的 0.9.5版本,而石英使用 0.9.1.1。这些版本相当不同,来自 quartz 的旧版本在我的类路径中排在第一位,导致运行时异常。由于我不使用 quartz 分布式作业存储,我通过排除传递 c3p0 依赖关系解决了这个问题:

    <dependency>
        <groupId>org.quartz-scheduler</groupId>
        <artifactId>quartz</artifactId>
        <version>2.2.1</version>
        <!-- old c3p0 (0.9.1.1) in class path causes destruction of ComboPooledDataSource-->
        <exclusions>
            <exclusion>
                <groupId>c3p0</groupId>
                <artifactId>c3p0</artifactId>
            </exclusion>
        </exclusions>
    </dependency>