Java 无法使用spring和hibrenate连接到postgres SQL
我有一个SpringWeb应用程序,我正在尝试与postgress连接。 下面是数据库连接属性Java 无法使用spring和hibrenate连接到postgres SQL,java,spring,hibernate,postgresql,Java,Spring,Hibernate,Postgresql,我有一个SpringWeb应用程序,我正在尝试与postgress连接。 下面是数据库连接属性 datasource.driver=org.postgresql.Driver datasource.url=jdbc:postgresql://localhost:5432/sampleDb datasource.username=postgres datasource.password=postgres 下面是应用程序上下文 <bean id="appDataSource" class="
datasource.driver=org.postgresql.Driver
datasource.url=jdbc:postgresql://localhost:5432/sampleDb
datasource.username=postgres
datasource.password=postgres
下面是应用程序上下文
<bean id="appDataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName">
<value>${datasource.driver}</value>
</property>
<property name="url">
<value>${datasource.url}</value>
</property>
<property name="username">
<value>${datasource.username}</value>
</property>
<property name="password">
<value>${datasource.password}</value>
</property>
</bean>
为什么会发生这种情况
我从另一台机器上恢复了这个数据库。我不知道他们在那个sql文件中写了什么。该sql转储文件中有一个代码
REVOKE ALL ON TABLE workflow_type FROM PUBLIC;
REVOKE ALL ON TABLE workflow_type FROM postgres;
GRANT ALL ON TABLE workflow_type TO postgres;
GRANT SELECT,INSERT,DELETE,REFERENCES,UPDATE ON TABLE workflow_type TO user1;
发生这种情况是因为此查询吗?您以前是否尝试在命令行下连接psql?这只是为了测试pg_hba.conf是否正常 如果无法连接到psql。打开pg_hba.conf文件,如果您在本地计算机上,请使用trust替换md5,以获得类似以下内容:
local all all trust
这允许每个人都连接到您的postgres服务器。
使用psql命令行重试连接
如果可以,请重试启动您的服务器,看看spring现在是否可以连接到db。您的Postgres是否已启动并在localhost:5432上运行?您是否能够通过命令行连接到数据库,例如psql-h localhost-U-W?保存您的pg_hba.conf,并通过信任更改所有md5,需要重新启动postgres,然后重试。您是否尝试通过命令行连接?它有效吗?
local all all trust