最近在做项目,开发时是通过driver创建datasource的,配置如下:
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${dataSource.driverClassName}" />
<property name="url" value="${dataSource.url}" />
<property name="username" value="${dataSource.username}" />
<property name="password" value="${dataSource.password}" />
</bean>
实施时是通过jndi查找得到datasource,配置如下:
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="${dataSource.jndiName}" />
</bean>
其中属性文件是通过propertyConfigurer导入的:
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
dependency-check="none">
<property name="fileEncoding" value="UTF-8" />
<property name="locations">
<list>
<value>classpath:spring-app.properties</value>
</list>
</property>
</bean>
文件的内容如下:
dataSource.jndiName=jdbc/myDataSource
dataSource.driverClassName=oracle.jdbc.driver.OracleDriver
dataSource.url=jdbc:oracle:thin:@localhost:1521:myServId
dataSource.usernam