Java Spring与Postgres DB的连接
正在尝试连接Postgres DB,上下文参数如下:Java Spring与Postgres DB的连接,java,spring,postgresql,spring-mvc,Java,Spring,Postgresql,Spring Mvc,正在尝试连接Postgres DB,上下文参数如下: <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource" > <property name="driverClassName" value="org.postgresql.Driver"/> <property name="url" value="jdbc:postgresql://local
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource" >
<property name="driverClassName" value="org.postgresql.Driver"/>
<property name="url" value="jdbc:postgresql://localhost:5432/****" />
<property name="username" value="****" />
<property name="password" value="****" />
</bean>
正在加载上下文时获取异常:
严重:上下文初始化失败
org.springframework.beans.factory.BeanCreationException:错误
正在创建在ServletContext中定义了名称为“dataSource”的bean
资源[/WEB-INF/ApplicationContext.xml]:设置属性时出错
价值观嵌套异常是
org.springframework.beans.PropertyBatchUpdateException;嵌套
PropertyAccessException(1)是:PropertyAccessException 1:
org.springframework.beans.MethodInvocationException:属性
“driverClassName”引发异常;嵌套异常是
java.lang.IllegalStateException:无法加载JDBC驱动程序类
[org.postgresql.Driver]
我在项目的库中有postgres驱动程序,因为我可以检查类文件org.postgresql.driver。Class.forName还为驱动程序类提供了一个积极的结果。
我已经尝试了所有版本的postgres驱动程序,但仍然没有成功。确保库被正确复制到包中,并且该目录位于类路径中。当我将postgres DB Jar添加到创建bean的WEBINF/lib时,我能够解决这个问题,有些人认为它没有像我以前那样从JavaResource/Lib中选择jar
这个问题在大多数地方都没有得到很好的回答,仅仅检查类路径并不能正确回答这个问题。所有这些都检查过了,我在其他lib中都有,我正在使用Spring lib和commons lib,目录在类路径中。对此的检查是我使用Class.forName(“org.postgresql.Driver”)来证明驱动程序在类路径中。还有其他线索,或者我能做的检查吗?你在用maven/gradle吗?你能发布你的pom/构建文件吗?