【问题标题】:BoneCp no suitable driver found Spring 3.1 Hibernate 4.0BoneCp 找不到合适的驱动程序 Spring 3.1 Hibernate 4.0
【发布时间】:2012-02-01 16:56:17
【问题描述】:

我目前正在使用 BoneCP 作为连接池管理器,因为没有真正的替代方案(c3p0 已死)。我正在使用hibernate 4和spring 3.1,一切正常。唯一困扰我的是自定义驱动程序的注册,例如oracle.jdbc.driver.OracleDriver

当应用程序启动并从数据库加载一些信息时,我收到以下消息:

java.sql.SQLException: 找不到适合 jdbc:oracle:thin:@localhost:xxx:xxxx 的驱动程序

数据源注册如下:

<bean id="mainDataSource" class="com.jolbox.bonecp.BoneCPDataSource" destroy method="close">
    <property name="driverClass" ref="hibernate.connection.driver_class" />
    <property name="jdbcUrl" ref="hibernate.connection.url" />
    <property name="username" ref="hibernate.connection.username" />
    <property name="password" ref="hibernate.connection.password" />
    <property name="poolName" ref="hibernate.connection.username"/>
...
</bean>

这个数据源然后被注入到一个会话工厂中。

当在 Eclipse 中的码头容器中运行此应用程序时,它可以完美运行。在 Tomcat 6.x 或 Websphere 8.x 上部署时,找不到指定的驱动程序。

我已经尝试将此驱动添加到spring datasourcemanager:

<bean id="myDataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" ref="hibernate.connection.driver_class"/>
    <property name="url" ref="hibernate.connection.url"/>
    <property name="username" ref="hibernate.connection.username"/>
    <property name="password" ref="hibernate.connection.password"/>
</bean>

这“解决了”我的问题,但现在从数据库加载数据时出现连接关闭异常。 (在启动时)。我可以使用我的应用程序,但有时会在随机时刻再次出现此连接关闭错误。

我看到 BoneCP 团队确认第一个问题为BoneCP bug,但尚未提交。我已尝试从这个错误跟踪器站点实施建议的解决方案,但我再次收到连接关闭错误。

有什么建议吗?

【问题讨论】:

    标签: hibernate spring oracle11g driver bonecp


    【解决方案1】:

    在我的例子中,有 两个 连接配置——一个在 hibernate.cfg.xml 中,第二个在 spring 中。 Hibernate 4.0 现在加载连接配置,如果它可以从 hibernate.cfg.xml 中获得,尽管存在 spring 连接配置 bean。

    所以只需从 spring 或 hibernate.cfg.xml 中删除第二个连接配置

    【讨论】:

      猜你喜欢
      • 2011-12-22
      • 1970-01-01
      • 2012-12-09
      • 2017-09-20
      • 2011-10-21
      • 1970-01-01
      • 2016-04-02
      • 2012-10-28
      相关资源
      最近更新 更多