【发布时间】:2011-12-22 05:29:13
【问题描述】:
我得到了心爱的错误:
java.sql.SQLException: No suitable driver found for jdbc:postgresql://localhost:5432/acme
我了解通常会出现此错误的许多原因:
- 无效的 URL: 该 URL 似乎没有任何错误,并且在 SQL Workbench 中运行良好。
- Driver Not on ClassPath:已成功导入(org.postgresql.Driver),可以直接实例化,也可以使用 Class.forName("org.postgresql.Driver") 实例化。
Hibernate SessionFactory 加载从 Spring-Bean 启动,但在运行时使用以下属性执行:
hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect
hibernate.connection.driver_class = org.postgresql.Driver
hibernate.connection.url = jdbc:postgresql://localhost:5432/acme
hibernate.connection.username = user
hibernate.connection.password = pass
我了解 Java DriverManager 在 OSGi 中不起作用,因此使用 DriverManager 注册驱动程序或实例化它以强制其注册无效。
有谁知道我该如何解决这个问题?有没有通用的解决方案?
提前致谢!
解决方案
正如 Andres Olarte 所指出的,我犯了一个错误,将驱动程序添加到 implementation bundle 中,但将其排除在 Hibernate 的类和依赖项所在的 Hibernate bundle 之外居住。
【问题讨论】:
标签: hibernate postgresql jdbc osgi equinox