无法使用 spring roo、eclipse、gwt 和 hibernate 连接到 postgresql 数据库
我刚刚开始使用 Roo,对它的可能性感到很兴奋。但是我在尝试连接到我的 postgresql 数据库时遇到问题。我搜索了他们的论坛和互联网,但没有解决我的问题。这是我的环境:
- Eclipse 3.6.1
- GWT 2.1.1
- SpringSource Tool Suite 2.5.2.RELEASE
- Spring Roo 1.1.1.RELEASE
- PostgreSQL v.8.3.11 数据库
我已采取的步骤: - 从 Spring Dashboard 创建了一个新的 Spring Roo 项目 - 打开roo shell并执行:
persistence setup --provider HIBERNATE --database POSTGRES
- 打开database.properties文件并添加:
--username - 密码 --url
返回 roo shell 并执行:
database introspect --schema no-schema-required
这会弹出一个对话框,显示可用于 postgresql 的附加组件 执行:
addon install id --searchResultId 01
roo 返回:
Target resource(s):
-------------------
spring-roo-postgres-jdbc4-wrapper (9.0.0.801_jdbc4_0001)
Deploying...done.
然后,当我自动完成数据库内省命令时,我得到:
database introspect --schema unable-to-obtain-connection
当我执行它时,我得到 JDBC 驱动程序不适用于 'org.postgresql.Driver'
所以,我假设我的连接属性不正确,但是我不确定。我们的数据库使用 SSL,我必须将以下内容添加到我的连接 url 中才能从我的其他项目进行连接:
jdbc:postgresql://10.104.0.41:5432/mydb?ssl=true&sslfactory=org.postgresql.ssl.NonValidatingFactory
这是我的 database.properties 文件的源代码:
database.driverClassName=org.postgresql.Driver
database.url=jdbc\:postgresql\://10.104.0.41\:5432/mydb
database.username=xxx
database.password=...
ssl=true
sslfactory=org.postgresql.ssl.NonValidatingFactory
我尝试删除文件中的 \ 而不做任何更改,并且我尝试过多种连接 URL 组合。我认为 url 是问题所在,但目前不确定。 昨天还有一件奇怪的事情,当我尝试使用 roo1.1.1.RELEASE 安装驱动程序附加组件时,由于关键认证问题而超时。我使用了 roo1.1.2.BUILD-SNAPSHOT 并且能够解决这个问题,但随后我在尝试运行 introspect 命令时会收到 NPE 错误。我今天重新安装了 SpringSource Tool Suite,删除了我的 .m2 存储库,并使用 roo1.1.1 启动了一个新项目,能够安装驱动程序,但现在无法连接。任何帮助将不胜感激,在我可以对一些表进行逆向工程之前,我有点陷入困境。 我还应该注意,我可以通过 Eclipse 中的数据源资源管理器使用这些连接属性和此连接 url 连接到数据库。我还连接了其他不使用 roo 和 hibernate 的项目。我还可以使用 roo 连接到本地 Derby 数据库。
非常感谢, 米奇
I'm just getting started using Roo and am excited about it's possibilities. However I am having problems trying to connect to my postgresql database. I have searched their forum and the internet without solving my problem. Here is my environment:
- Eclipse 3.6.1
- GWT 2.1.1
- SpringSource Tool Suite 2.5.2.RELEASE
- Spring Roo 1.1.1.RELEASE
- PostgreSQL v.8.3.11 database
Steps I have taken:
- Created a new Spring Roo project from the Spring Dashboard
- Opened roo shell and executed:
persistence setup --provider HIBERNATE --database POSTGRES
- Opened the database.properties file and added:
--username
--password
--url
back to roo shell and executed:
database introspect --schema no-schema-required
This brought up the dialog showing the add-ons available for postgresql
executed:
addon install id --searchResultId 01
roo returned:
Target resource(s):
-------------------
spring-roo-postgres-jdbc4-wrapper (9.0.0.801_jdbc4_0001)
Deploying...done.
Then when I auto complete the database introspect command I get:
database introspect --schema unable-to-obtain-connection
and when I execute it I get the JDBC driver not available for 'org.postgresql.Driver'
So, I am assuming my connection properties are not right, but am not sure. Our database uses SSL and I have had to add the following to my connection url to connect from my other projects:
jdbc:postgresql://10.104.0.41:5432/mydb?ssl=true&sslfactory=org.postgresql.ssl.NonValidatingFactory
Here is the source from my database.properties file:
database.driverClassName=org.postgresql.Driver
database.url=jdbc\:postgresql\://10.104.0.41\:5432/mydb
database.username=xxx
database.password=...
ssl=true
sslfactory=org.postgresql.ssl.NonValidatingFactory
I have tried removing the \ 's in the file with no change and I have tried a variety of connection url combinations. I'm thinking the url is the problem, but am not sure at this point.
Also something weird is yesterday when I tried to install the driver add-on using the roo1.1.1.RELEASE I got a timeout because of a key certification issue. I used the roo1.1.2.BUILD-SNAPSHOT and was able to get around that, but then I would get an NPE error trying to run the introspect command. I installed SpringSource Tool Suite fresh today, deleted my .m2 repository, and started a new project using roo1.1.1, was able to install the driver but now can't get connected. Any help would be much appreciated, I'm kinda stuck until I can reverse engineer some tables.
I should also note that I can connect to the database through the data source explorer in eclipse with these connection properties and this connection url. I have also connected in other projects that were not using roo and hibernate. I can also connect to a local Derby database with roo.
Thanks so much,
Mitch
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于那些现在登陆此页面的人。要解决该问题,您必须执行:
因为如果您使用较新的 Postgre,则 9.0.801.0001 Postgres 是正确的版本。
For those who land on this page now. To solve the problem you have to execute:
because 9.0.801.0001 Postgres is the correct version if your using newer Postgre.
我对“roo”一无所知,因此,您可能需要调整我的答案以使其适用于 roo。
这意味着 JDBC 驱动程序 JAR 不在您的类路径中。转到此页面,下载适当的驱动程序(JDBC 4,如果您有疑问),然后将其添加到您的类路径中。如果您使用maven,您可能需要添加此依赖项(调整版本标记):
I don't know anything about "roo", so, you may want to adapt my answer to make it work with roo.
It means that the JDBC driver JAR is not in your classpath. Go to this page, download the appropriate driver (JDBC 4, if you are in doubt), and add it to your classpath. If you are using maven, you may want to add this dependency (adapt the version tag):