1 概要
在一些Spring工程中,有时对于数据的展示和处理需要涉及到多种数据库,本文以在IDEA中将PostgreSQL数据库通过连接池的方式连接到maven项目为例进行说明。
2 连接
2.1 pom.xml
在pom.xml文件的<dependencies></dependencies>中添加如下依赖(其中<version></version>中为版本号,可自行调整):
<dependency>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>8.2-507.jdbc3</version>
</dependency>
保存pom.xml后点击“Load Maven Changes”,如下图:

重启项目后,可以看到target的lib文件夹下新增了“postgresql-8.2-507.jdbc3.jar”
2.2 Spring配置
在resources/spring/dao中对应业务文件的xml中添加如下内容:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
x

最低0.47元/天 解锁文章
676





