[英]Advantage of org.springframework.jdbc.datasource.DriverManagerDataSource over oracle.jdbc.pool.OracleDataSource
I currently use this configuration for my projects: 我目前在我的项目中使用以下配置:
<bean id="dataSource" class="oracle.jdbc.pool.OracleDataSource"
destroy-method="close">
<property name="URL" ...
<property name="user" ...
<property name="password" ...
<property name="connectionCachingEnabled" value="true" />
And it works fine, pretty fast. 而且效果很好,非常快。 I happened to see, on an old project (spring 2.5) this configuration: 我碰巧看到,在一个旧项目(Spring 2.5)中,这种配置:
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName">
<value>oracle.jdbc.driver.OracleDriver</value>
</property>
<property name="url"...
<property name="username" ...
<property name="password" ...
</bean>
From documentation it would seem that this last option does not make use of a connection pool. 从文档看来,这最后一个选项没有利用连接池。 I see no reason to use this configuration over mine, but it still exists so I am curious: where's the advantage/limitation? 我认为没有理由在我的产品上使用此配置,但是它仍然存在,所以我很好奇:优势/局限在哪里?
1st configuration is oracle specific, whereas 2nd configuration is generic. 第一种配置是oracle特定的,而第二种配置是通用的。 You can explicitly define driver class. 您可以显式定义驱动程序类。 This is the only major difference I can see in them other than connection pool support of OracleDataSource. 除了对OracleDataSource的连接池的支持外,这是我可以看到的唯一主要区别。
You can use it for generic behavior as mentioned below: 您可以将其用于一般行为,如下所述:
<bean id="baseDataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource"
abstract="true">
<property name="username" value="user"/>
<property name="password" value="pwd" />
</bean>
<bean id="mySqlDataSource" parent="baseDataSource">
<property name="driverClassName" value="${mySQL.driver}" />
<property name="url" value="${mySQL.url}"/>
</bean>
<bean id="oracleDataSource" parent="baseDataSource">
<property name="driverClassName" value="${oracle.driver}" />
<property name="url" value="${oracle.url}"/>
</bean>
Property values you can externalized. 您可以外部化属性值。
You can explore Apache Jakarta Commons DBCP which has all the features of DriverManagerDataSource along with connection pool feature. 您可以探索Apache Jakarta Commons DBCP,它具有DriverManagerDataSource的所有功能以及连接池功能。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.