Java 通过SpringXML数据源配置postgresql驱动程序
我一直在尝试配置使用xml Spring配置文件中声明的postgresql数据源进行的连接Java 通过SpringXML数据源配置postgresql驱动程序,java,sql,spring,postgresql,Java,Sql,Spring,Postgresql,我一直在尝试配置使用xml Spring配置文件中声明的postgresql数据源进行的连接 <bean id="myDataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="org.postgresql.Driver" /> <prop
<bean id="myDataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="org.postgresql.Driver" />
<property name="url" value="jdbc:postgresql://localhost:5432/dbname" />
<property name="username" value="postgres" />
<property name="password" value="" />
<property name="socketTimeout" value="10"/>
</bean>
我甚至可以使用DriverManager数据源执行此操作吗?我试着搜索,但没有找到任何有用的东西,因为没有很多人真正使用它。谢谢你,迪纳姆先生,我找到了方法。 事实上,即使知道这个属性被命名为“connectionProperties”,我也没有找到很多答案(也许人们很少这样使用它?)。所以我把它贴出来:
<bean id="myDataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="org.postgresql.Driver" />
<property name="url" value="jdbc:postgresql://localhost:5432/dbname" />
<property name="username" value="postgres" />
<property name="password" value="" />
<!--<property name="socketTimeout" value="10"/>-->
<property name="connectionProperties">
<props>
<prop key="socketTimeout">10</prop>
</props>
</property>
</bean>
10
如果有人有更好/更完整的答案,我会查看;) 这就是为什么有一个采用
Properties
元素的connectionProperties
属性。再加上它。
<bean id="myDataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="org.postgresql.Driver" />
<property name="url" value="jdbc:postgresql://localhost:5432/dbname" />
<property name="username" value="postgres" />
<property name="password" value="" />
<!--<property name="socketTimeout" value="10"/>-->
<property name="connectionProperties">
<props>
<prop key="socketTimeout">10</prop>
</props>
</property>
</bean>