Announcement Announcement Module
Collapse
No announcement yet.
Multiple DataSource Connection Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Multiple DataSource Connection

    I don't know if this has been asked before or not but i have multiple bean in applicationContext.xml which connects to two different connection :-

    Code:
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" >
    		<property name="driverClassName">
    			<value>${enroll.jdbc.driver}</value>
    		</property>
    		<property name="url">
    			<value>${enroll.jdbc.url}</value>
    		</property>
    		<property name="username">
    			<value>${enroll.jdbc.username}</value>
    		</property>
    		<property name="password">
    			<value>${enroll.jdbc.password}</value>
    		</property>
    	</bean>
    
    
    <bean id="employeeDataSource" class="org.apache.commons.dbcp.BasicDataSource" >
    		<property name="driverClassName">
    			<value>${employee.jdbc.driver}</value>
    		</property>
    		<property name="url">
    			<value>${employee.jdbc.url}</value>
    		</property>
    		<property name="username">
    			<value>${employee.jdbc.username}</value>
    		</property>
    		<property name="password">
    			<value>${employee.jdbc.password}</value>
    		</property>
    	</bean>
    
    	<bean id="enrollService" class="com.enroll.EnrollServiceImpl">
    	<property name="enrollDao"><ref bean="enrollDao"/></property>
    	</bean>
    	
    
    	<bean  id="enrollDao" class="com.enroll.EnrollDaoImpl" init-method="initialize">
    	<property name="dataSource"><ref bean="dataSource"/></property>
    	</bean>
    
    	<bean id="employeeService" class="com.employee.EmployeeServiceImpl">
    	<property name="employeeDao"><ref bean="employeeDao"/></property>
    	</bean>
    	
    
    	<bean  id="employeeDao" class="com.enroll.EmployeeDaoImpl" init-method="initialize">
    	<property name="dataSource"><ref bean="employeeDataSource"/></property>
    	</bean>
    Now in my employeeDao class i would like to connect to enrol database to get some data from couple of tables which belong to enroll database. If i plan to use regular jdbc i know i can have a connection string url where i can specify the settings, username and password but my question is that is it possible to connect to enroll datasource in my employeeDao using spring datasource which is already defined in applicationContext ?
    Last edited by christopher1234; Jun 10th, 2009, 09:19 PM.
Working...
X