<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Dynamic DataSource Routing</title>
	<atom:link href="http://blog.springsource.org/2007/01/23/dynamic-datasource-routing/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.springsource.org/2007/01/23/dynamic-datasource-routing/</link>
	<description>The voice of SpringSource</description>
	<lastBuildDate>Wed, 08 Feb 2012 17:31:53 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.1</generator>
	<item>
		<title>By: Thangaraj</title>
		<link>http://blog.springsource.org/2007/01/23/dynamic-datasource-routing/comment-page-3/#comment-234580</link>
		<dc:creator>Thangaraj</dc:creator>
		<pubDate>Thu, 29 Dec 2011 16:54:40 +0000</pubDate>
		<guid isPermaLink="false">http://blog.interface21.com/main/2007/01/23/dynamic-datasource-routing/#comment-234580</guid>
		<description>forgot to ask... continued...
...how will you pass values to the place of database configuration from database dynamically.</description>
		<content:encoded><![CDATA[<p>forgot to ask&#8230; continued&#8230;<br />
&#8230;how will you pass values to the place of database configuration from database dynamically.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Thangaraj</title>
		<link>http://blog.springsource.org/2007/01/23/dynamic-datasource-routing/comment-page-3/#comment-234578</link>
		<dc:creator>Thangaraj</dc:creator>
		<pubDate>Thu, 29 Dec 2011 15:40:56 +0000</pubDate>
		<guid isPermaLink="false">http://blog.interface21.com/main/2007/01/23/dynamic-datasource-routing/#comment-234578</guid>
		<description>Hi,
The article is interesting!. But it seems hard coded datasources not dynamically.  May be i have misunderstood. Anyway, how will you pass values to the place of database configuration.

Hope you reply soon!</description>
		<content:encoded><![CDATA[<p>Hi,<br />
The article is interesting!. But it seems hard coded datasources not dynamically.  May be i have misunderstood. Anyway, how will you pass values to the place of database configuration.</p>
<p>Hope you reply soon!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Spring @Async and the AbstractRoutingDataSource</title>
		<link>http://blog.springsource.org/2007/01/23/dynamic-datasource-routing/comment-page-3/#comment-205228</link>
		<dc:creator>Spring @Async and the AbstractRoutingDataSource</dc:creator>
		<pubDate>Mon, 10 Oct 2011 21:29:09 +0000</pubDate>
		<guid isPermaLink="false">http://blog.interface21.com/main/2007/01/23/dynamic-datasource-routing/#comment-205228</guid>
		<description>[...] been using the AbstractRoutingDataSource with great success, but have hit upon an issue I can&#8217;t resolve: when I kick off an [...]</description>
		<content:encoded><![CDATA[<p>[...] been using the AbstractRoutingDataSource with great success, but have hit upon an issue I can&#039;t resolve: when I kick off an [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Aravindan</title>
		<link>http://blog.springsource.org/2007/01/23/dynamic-datasource-routing/comment-page-3/#comment-202134</link>
		<dc:creator>Aravindan</dc:creator>
		<pubDate>Tue, 13 Sep 2011 11:38:00 +0000</pubDate>
		<guid isPermaLink="false">http://blog.interface21.com/main/2007/01/23/dynamic-datasource-routing/#comment-202134</guid>
		<description>Hi,
  
  Here in the above example i see the Database details i.e URL/Port/UserName/Password will be know and its configured in properties file for the different Database&#039;s that we need to use. But I have a simillar use case where the datadase name will be dynamic i.e we need to get the database name i.e &quot;User_Product_Profile&quot;  by passing the username and product details when the user selects the product. Basically the mapping of database that we need to use for each username and product will be get from a different database i.e DB_Profile Table of Customer Database. 

Please let me know how to configure such use case with spring.

Thanks,
 Aravindan</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>  Here in the above example i see the Database details i.e URL/Port/UserName/Password will be know and its configured in properties file for the different Database&#039;s that we need to use. But I have a simillar use case where the datadase name will be dynamic i.e we need to get the database name i.e &#034;User_Product_Profile&#034;  by passing the username and product details when the user selects the product. Basically the mapping of database that we need to use for each username and product will be get from a different database i.e DB_Profile Table of Customer Database. </p>
<p>Please let me know how to configure such use case with spring.</p>
<p>Thanks,<br />
 Aravindan</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: prabuddha roy</title>
		<link>http://blog.springsource.org/2007/01/23/dynamic-datasource-routing/comment-page-3/#comment-199380</link>
		<dc:creator>prabuddha roy</dc:creator>
		<pubDate>Wed, 03 Aug 2011 16:12:48 +0000</pubDate>
		<guid isPermaLink="false">http://blog.interface21.com/main/2007/01/23/dynamic-datasource-routing/#comment-199380</guid>
		<description>Hi Mark,
       Please let us know if you figure out the Hibernate SessionFactory usage with your approach. You promised long time back as quoted below.
       Hope you are still actively following your invention feedback.


[Mark Fisher (blog author) says:
Added on April 5th, 2007 at 3:35 pm

Ken, it is true that you could avoid collisions through globally-unique identifiers. However, it seems that the ideal solution would involve dynamically routing to different SessionFactory instances. I plan to post a follow-up that addresses that within the next few days.]</description>
		<content:encoded><![CDATA[<p>Hi Mark,<br />
       Please let us know if you figure out the Hibernate SessionFactory usage with your approach. You promised long time back as quoted below.<br />
       Hope you are still actively following your invention feedback.</p>
<p>[Mark Fisher (blog author) says:<br />
Added on April 5th, 2007 at 3:35 pm</p>
<p>Ken, it is true that you could avoid collisions through globally-unique identifiers. However, it seems that the ideal solution would involve dynamically routing to different SessionFactory instances. I plan to post a follow-up that addresses that within the next few days.]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Saravana</title>
		<link>http://blog.springsource.org/2007/01/23/dynamic-datasource-routing/comment-page-3/#comment-198356</link>
		<dc:creator>Saravana</dc:creator>
		<pubDate>Wed, 13 Jul 2011 05:24:56 +0000</pubDate>
		<guid isPermaLink="false">http://blog.interface21.com/main/2007/01/23/dynamic-datasource-routing/#comment-198356</guid>
		<description>Hi, I am facing an issue. I have configured two data sources one is JNDI based which is used for production. Other is DriverManager based which is used for testing. I am using the second datasource to be used when running unit tests(without the app server). But both of my data sources are trying to get created, only that the usage of the data source is determined based on the type set in the context. I tried setting lazy-init=&quot;true&quot; for Production Data source bean but no use.</description>
		<content:encoded><![CDATA[<p>Hi, I am facing an issue. I have configured two data sources one is JNDI based which is used for production. Other is DriverManager based which is used for testing. I am using the second datasource to be used when running unit tests(without the app server). But both of my data sources are trying to get created, only that the usage of the data source is determined based on the type set in the context. I tried setting lazy-init=&#034;true&#034; for Production Data source bean but no use.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Spring实现数据库读写分离 &#124; Neo 时刻准备着</title>
		<link>http://blog.springsource.org/2007/01/23/dynamic-datasource-routing/comment-page-3/#comment-195232</link>
		<dc:creator>Spring实现数据库读写分离 &#124; Neo 时刻准备着</dc:creator>
		<pubDate>Sat, 11 Jun 2011 14:46:51 +0000</pubDate>
		<guid isPermaLink="false">http://blog.interface21.com/main/2007/01/23/dynamic-datasource-routing/#comment-195232</guid>
		<description>[...] Spring实现数据库读写分离 借助于Spring框架在2.0.1之后提供的AbstractRoutingDataSource可以实现动态的选择数据源datasource，下面先举一个最简单的例子（可以参考这个链接）： &#160; 1. 首先新建一个Catalog VO对象的DAO（见代码1），它继承了SimpleJdbcDaoSupport，JdbcDaoSupport需要注入一个DataSource，同时也提供了操作模板JdbcTemplate。添加一个方法用于获取所有的&#8220;货物Item&#8221;。货物Iteam是一个POJO类（见代码2）。 &#160; 代码1:  import java.sql.ResultSet; import java.sql.SQLException; import java.util.List; import org.springframework.jdbc.core.simple.ParameterizedRowMapper; import org.springframework.jdbc.core.simple.SimpleJdbcDaoSupport; &#160; public class Catalog extends SimpleJdbcDaoSupport &#123; &#160; public List&lt;Item&gt; getItems&#040;&#041; &#123; String query = &quot;select name, price from item&quot;; return getSimpleJdbcTemplate&#040;&#041;.query&#040;query, new ParameterizedRowMapper&lt;Item&gt;&#040;&#041; &#123; public Item mapRow&#040;ResultSet rs, int row&#041; throws SQLException &#123; String name = rs.getString&#040;1&#041;; double price = rs.getDouble&#040;2&#041;; return new Item&#040;name, price&#041;; &#125; &#125;&#041;; &#125; &#125;  &#160; 代码2：  public class Item &#123; &#160; private String name; private double price; &#160; public Item&#040;String name, double price&#041; &#123; this.name = name; this.price = price; &#125; &#160; public String getName&#040;&#041; &#123; return name; &#125; &#160; public double getPrice&#040;&#041; &#123; return price; &#125; &#160; public String toString&#040;&#041; &#123; return name + &quot; (&quot; + price + &quot;)&quot;; &#125; &#160; &#125;  &#160; &#160; 2． 配置Spring多数据源，这里配置了一个主库和一个从库，他们可以共同继承一个父的数据源。 代码3：  &lt;bean id=&quot;parentDataSource&quot;  class=&quot;org.springframework.jdbc.datasource.DriverManagerDataSource&quot;  abstract=&quot;true&quot;&gt; &lt;property name=&quot;driverClassName&quot; value=&quot;com.mysql.jdbc.Driver&quot;/&gt; &lt;property name=&quot;username&quot; value=&quot;test&quot;/&gt; &lt;/bean&gt; &#160; &lt;!-- 主库 --&gt; &lt;bean id=&quot;masterDataSource&quot; parent=&quot;parentDataSource&quot;&gt; &lt;property name=&quot;url&quot; value=&quot;jdbc:mysql://localhost:${db.port.master}/blog&quot;/&gt; &lt;/bean&gt; &#160; &lt;!-- 从库 --&gt; &lt;bean id=&quot;slaveDataSource&quot; parent=&quot;parentDataSource&quot;&gt; &lt;property name=&quot;url&quot; value=&quot;jdbc:mysql://localhost:${db.port.slave}/blog&quot;/&gt; &lt;/bean&gt; &#160; &lt;!-- 用PropertyPlaceholderConfigurer来读取properties配置，此处省略配置 --&gt; &lt;bean class=&quot;org.springframework.beans.factory.config.PropertyPlaceholderConfigurer&quot;&gt; &lt;property name=&quot;location&quot; value=&quot;classpath:/blog/datasource/db.properties&quot;/&gt; &lt;/bean&gt;  &#160; &#160; 3． 新建一个datasource继承自AbstractRoutingDataSource，并且覆盖determineCurrentLookupKey()方法，每次用这个datasource获取数据库连接的时候都会回调这个方法获得key，根据返回的字符串key（也可以是枚举值，数字类型），动态地通过datasource配置的id来在Spring的配置文件中找到相应的datasource来获取connection（见代码4）。那么如果每次访问都需要根据key来决定如何选择数据源，那么这个key必须要保证线程安全，并发情况下每个线程都会去寻找本应该属于自己的key获取数据源，所以CustomerContextHolder类中就用到了ThreadLocal来保证（见代码5）。 &#160; 代码4：  import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource; &#160; public class CustomerRoutingDataSource extends AbstractRoutingDataSource &#123; &#160; @Override protected Object determineCurrentLookupKey&#040;&#041; &#123; return CustomerContextHolder.getCustomerType&#040;&#041;; &#125; &#125;  &#160; 代码5：  public class CustomerContextHolder &#123; &#160; private static final ThreadLocal&lt;String&gt; contextHolder = new ThreadLocal&lt;String&gt;&#040;&#041;; &#160; public static void setCustomerType&#040;String customerType&#041; &#123; Assert.notNull&#040;customerType, &quot;customerType cannot be null&quot;&#041;; contextHolder.set&#040;customerType&#041;; &#125; &#160; public static String getCustomerType&#040;&#041; &#123; return &#040;String&#041; contextHolder.get&#040;&#041;; &#125; &#160; public static void clearCustomerType&#040;&#041; &#123; contextHolder.remove&#040;&#041;; &#125; &#125;  &#160; &#160; 在Spring中的配置如下： &#160; 代码6：  &lt;bean id=&quot;catalog&quot; class=&quot;blog.datasource.Catalog&quot;&gt; &lt;property name=&quot;dataSource&quot; ref=&quot;dataSource&quot;/&gt; &lt;/bean&gt; &#160; &lt;bean id=&quot;dataSource&quot; class=&quot;blog.datasource.CustomerRoutingDataSource&quot;&gt; &lt;!-- 这个targetDataSource是必须要注入的 --&gt; &lt;property name=&quot;targetDataSources&quot;&gt; &lt;map key-type=&quot;java.lang.String&quot;&gt; &lt;entry key=&quot;MASTER&quot; value-ref=&quot;masterDataSource&quot;/&gt; &lt;entry key=&quot;SLAVE&quot; value-ref=&quot;slaveDataSource&quot;/&gt; &lt;/map&gt; &lt;/property&gt; &lt;!-- 默认的数据源 --&gt; &lt;property name=&quot;defaultTargetDataSource&quot; ref=&quot;masterDataSource&quot;/&gt; &lt;/bean&gt;  &#160; &#160; 4． 测试用例 &#160; 代码7：  AbstractDependencyInjectionSpringContextTests &#123; &#160; private Catalog catalog; &#160; public void setCatalog&#040;Catalog catalog&#041; &#123; this.catalog = catalog; &#125; &#160; public void testDataSourceRouting&#040;&#041; &#123; CustomerContextHolder.setCustomerType&#040;“MASTER”&#041;; List&lt;Item&gt; goldItems = catalog.getItems&#040;&#041;; assertEquals&#040;3, goldItems.size&#040;&#041;&#041;; System.out.println&#040;&quot;gold items: &quot; + goldItems&#041;; &#160; CustomerContextHolder.setCustomerType&#040;“SLAVE”&#041;; List&lt;Item&gt; silverItems = catalog.getItems&#040;&#041;; assertEquals&#040;2, silverItems.size&#040;&#041;&#041;; System.out.println&#040;&quot;silver items: &quot; + silverItems&#041;; &#160; CustomerContextHolder.clearCustomerType&#040;&#041;; List&lt;Item&gt; bronzeItems = catalog.getItems&#040;&#041;; assertEquals&#040;1, bronzeItems.size&#040;&#041;&#041;; System.out.println&#040;&quot;bronze items: &quot; + bronzeItems&#041;; &#125; &#160; protected String&#091;&#093; getConfigLocations&#040;&#041; &#123; return new String&#091;&#093; &#123;&quot;/blog/datasource/beans.xml&quot;&#125;; &#125; &#125;   June 11th, 2011 in J2EE &#124; tags: J2EE, Spring, 读写分离 [...]</description>
		<content:encoded><![CDATA[<p>[...] Spring实现数据库读写分离 借助于Spring框架在2.0.1之后提供的AbstractRoutingDataSource可以实现动态的选择数据源datasource，下面先举一个最简单的例子（可以参考这个链接）： &nbsp; 1. 首先新建一个Catalog VO对象的DAO（见代码1），它继承了SimpleJdbcDaoSupport，JdbcDaoSupport需要注入一个DataSource，同时也提供了操作模板JdbcTemplate。添加一个方法用于获取所有的&ldquo;货物Item&rdquo;。货物Iteam是一个POJO类（见代码2）。 &nbsp; 代码1:  import java.sql.ResultSet; import java.sql.SQLException; import java.util.List; import org.springframework.jdbc.core.simple.ParameterizedRowMapper; import org.springframework.jdbc.core.simple.SimpleJdbcDaoSupport; &nbsp; public class Catalog extends SimpleJdbcDaoSupport &#123; &nbsp; public List&lt;Item&gt; getItems&#040;&#041; &#123; String query = &quot;select name, price from item&quot;; return getSimpleJdbcTemplate&#040;&#041;.query&#040;query, new ParameterizedRowMapper&lt;Item&gt;&#040;&#041; &#123; public Item mapRow&#040;ResultSet rs, int row&#041; throws SQLException &#123; String name = rs.getString&#040;1&#041;; double price = rs.getDouble&#040;2&#041;; return new Item&#040;name, price&#041;; &#125; &#125;&#041;; &#125; &#125;  &nbsp; 代码2：  public class Item &#123; &nbsp; private String name; private double price; &nbsp; public Item&#040;String name, double price&#041; &#123; this.name = name; this.price = price; &#125; &nbsp; public String getName&#040;&#041; &#123; return name; &#125; &nbsp; public double getPrice&#040;&#041; &#123; return price; &#125; &nbsp; public String toString&#040;&#041; &#123; return name + &quot; (&quot; + price + &quot;)&quot;; &#125; &nbsp; &#125;  &nbsp; &nbsp; 2． 配置Spring多数据源，这里配置了一个主库和一个从库，他们可以共同继承一个父的数据源。 代码3：  &lt;bean id=&quot;parentDataSource&quot;  class=&quot;org.springframework.jdbc.datasource.DriverManagerDataSource&quot;  abstract=&quot;true&quot;&gt; &lt;property name=&quot;driverClassName&quot; value=&quot;com.mysql.jdbc.Driver&quot;/&gt; &lt;property name=&quot;username&quot; value=&quot;test&quot;/&gt; &lt;/bean&gt; &nbsp; &lt;!&#8211; 主库 &#8211;&gt; &lt;bean id=&quot;masterDataSource&quot; parent=&quot;parentDataSource&quot;&gt; &lt;property name=&quot;url&quot; value=&quot;jdbc:mysql://localhost:${db.port.master}/blog&quot;/&gt; &lt;/bean&gt; &nbsp; &lt;!&#8211; 从库 &#8211;&gt; &lt;bean id=&quot;slaveDataSource&quot; parent=&quot;parentDataSource&quot;&gt; &lt;property name=&quot;url&quot; value=&quot;jdbc:mysql://localhost:${db.port.slave}/blog&quot;/&gt; &lt;/bean&gt; &nbsp; &lt;!&#8211; 用PropertyPlaceholderConfigurer来读取properties配置，此处省略配置 &#8211;&gt; &lt;bean class=&quot;org.springframework.beans.factory.config.PropertyPlaceholderConfigurer&quot;&gt; &lt;property name=&quot;location&quot; value=&quot;classpath:/blog/datasource/db.properties&quot;/&gt; &lt;/bean&gt;  &nbsp; &nbsp; 3． 新建一个datasource继承自AbstractRoutingDataSource，并且覆盖determineCurrentLookupKey()方法，每次用这个datasource获取数据库连接的时候都会回调这个方法获得key，根据返回的字符串key（也可以是枚举值，数字类型），动态地通过datasource配置的id来在Spring的配置文件中找到相应的datasource来获取connection（见代码4）。那么如果每次访问都需要根据key来决定如何选择数据源，那么这个key必须要保证线程安全，并发情况下每个线程都会去寻找本应该属于自己的key获取数据源，所以CustomerContextHolder类中就用到了ThreadLocal来保证（见代码5）。 &nbsp; 代码4：  import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource; &nbsp; public class CustomerRoutingDataSource extends AbstractRoutingDataSource &#123; &nbsp; @Override protected Object determineCurrentLookupKey&#040;&#041; &#123; return CustomerContextHolder.getCustomerType&#040;&#041;; &#125; &#125;  &nbsp; 代码5：  public class CustomerContextHolder &#123; &nbsp; private static final ThreadLocal&lt;String&gt; contextHolder = new ThreadLocal&lt;String&gt;&#040;&#041;; &nbsp; public static void setCustomerType&#040;String customerType&#041; &#123; Assert.notNull&#040;customerType, &quot;customerType cannot be null&quot;&#041;; contextHolder.set&#040;customerType&#041;; &#125; &nbsp; public static String getCustomerType&#040;&#041; &#123; return &#040;String&#041; contextHolder.get&#040;&#041;; &#125; &nbsp; public static void clearCustomerType&#040;&#041; &#123; contextHolder.remove&#040;&#041;; &#125; &#125;  &nbsp; &nbsp; 在Spring中的配置如下： &nbsp; 代码6：  &lt;bean id=&quot;catalog&quot; class=&quot;blog.datasource.Catalog&quot;&gt; &lt;property name=&quot;dataSource&quot; ref=&quot;dataSource&quot;/&gt; &lt;/bean&gt; &nbsp; &lt;bean id=&quot;dataSource&quot; class=&quot;blog.datasource.CustomerRoutingDataSource&quot;&gt; &lt;!&#8211; 这个targetDataSource是必须要注入的 &#8211;&gt; &lt;property name=&quot;targetDataSources&quot;&gt; &lt;map key-type=&quot;java.lang.String&quot;&gt; &lt;entry key=&quot;MASTER&quot; value-ref=&quot;masterDataSource&quot;/&gt; &lt;entry key=&quot;SLAVE&quot; value-ref=&quot;slaveDataSource&quot;/&gt; &lt;/map&gt; &lt;/property&gt; &lt;!&#8211; 默认的数据源 &#8211;&gt; &lt;property name=&quot;defaultTargetDataSource&quot; ref=&quot;masterDataSource&quot;/&gt; &lt;/bean&gt;  &nbsp; &nbsp; 4． 测试用例 &nbsp; 代码7：  AbstractDependencyInjectionSpringContextTests &#123; &nbsp; private Catalog catalog; &nbsp; public void setCatalog&#040;Catalog catalog&#041; &#123; this.catalog = catalog; &#125; &nbsp; public void testDataSourceRouting&#040;&#041; &#123; CustomerContextHolder.setCustomerType&#040;“MASTER”&#041;; List&lt;Item&gt; goldItems = catalog.getItems&#040;&#041;; assertEquals&#040;3, goldItems.size&#040;&#041;&#041;; System.out.println&#040;&quot;gold items: &quot; + goldItems&#041;; &nbsp; CustomerContextHolder.setCustomerType&#040;“SLAVE”&#041;; List&lt;Item&gt; silverItems = catalog.getItems&#040;&#041;; assertEquals&#040;2, silverItems.size&#040;&#041;&#041;; System.out.println&#040;&quot;silver items: &quot; + silverItems&#041;; &nbsp; CustomerContextHolder.clearCustomerType&#040;&#041;; List&lt;Item&gt; bronzeItems = catalog.getItems&#040;&#041;; assertEquals&#040;1, bronzeItems.size&#040;&#041;&#041;; System.out.println&#040;&quot;bronze items: &quot; + bronzeItems&#041;; &#125; &nbsp; protected String&#091;&#093; getConfigLocations&#040;&#041; &#123; return new String&#091;&#093; &#123;&quot;/blog/datasource/beans.xml&quot;&#125;; &#125; &#125;   June 11th, 2011 in J2EE | tags: J2EE, Spring, 读写分离 [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jose</title>
		<link>http://blog.springsource.org/2007/01/23/dynamic-datasource-routing/comment-page-3/#comment-193347</link>
		<dc:creator>Jose</dc:creator>
		<pubDate>Thu, 05 May 2011 18:11:26 +0000</pubDate>
		<guid isPermaLink="false">http://blog.interface21.com/main/2007/01/23/dynamic-datasource-routing/#comment-193347</guid>
		<description>Hey I can access to a different databases, how can do it? thanks</description>
		<content:encoded><![CDATA[<p>Hey I can access to a different databases, how can do it? thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kyle</title>
		<link>http://blog.springsource.org/2007/01/23/dynamic-datasource-routing/comment-page-2/#comment-192247</link>
		<dc:creator>Kyle</dc:creator>
		<pubDate>Thu, 14 Apr 2011 11:07:32 +0000</pubDate>
		<guid isPermaLink="false">http://blog.interface21.com/main/2007/01/23/dynamic-datasource-routing/#comment-192247</guid>
		<description>My issue has been resolved BTW. I just had to remove the transactional annotations.</description>
		<content:encoded><![CDATA[<p>My issue has been resolved BTW. I just had to remove the transactional annotations.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ricardo</title>
		<link>http://blog.springsource.org/2007/01/23/dynamic-datasource-routing/comment-page-2/#comment-192243</link>
		<dc:creator>Ricardo</dc:creator>
		<pubDate>Thu, 14 Apr 2011 09:30:49 +0000</pubDate>
		<guid isPermaLink="false">http://blog.interface21.com/main/2007/01/23/dynamic-datasource-routing/#comment-192243</guid>
		<description>Im getting a null pointer exception:
============================================
//DAO
public class TestDAO extends SimpleJdbcDaoSupport { 
    
    public List&lt;Map&gt; getDomains() {
        String query = &quot;select 1 from dual&quot;;        
        return getSimpleJdbcTemplate().queryForList(query);
    }
}
============================================
//Routing
public class RoutingDataSource extends AbstractRoutingDataSource {
    @Override
    protected Object determineCurrentLookupKey() {
        return SessionContextHolder.getDBServer();
    }
}
============================================
//controller
@Controller
@RequestMapping(value=&quot;/test&quot;)
public class HandleRequest {
 
    
    @RequestMapping(method=RequestMethod.GET)   
    public String handle(Model model){
   
        TestDAO testDAO = new TestDAO();
        
        SessionContextHolder.setDBServer(&quot;server1&quot;);        
        
        List domains = testDAO.getDomains();
        
        model.addAttribute(&quot;domains&quot;, domains);
        return &quot;test1&quot;;
    }
}
============================================


	
	&lt;!-- Scans the classpath of this application for @Components to deploy as beans --&gt;
	

	&lt;!-- Configures the @Controller programming model --&gt;
	
     
    
		    	
		
		
		
	
	
    
 	
    	      	
        
    	
      	
      	
      	
      	
      	
      	
      	
      	
      	
	 


 	
    	
	 
	 	 
	
	   
	
	 
	
	   
	

	 
	
	   
		
    
    
    	
	
	
	
   		
	

	
   		
    		
        		
         		
         		
      		
   		
   		
	
	
	
	&lt;!--  properties file --&gt;
	


============================================


And this is the error

java.lang.NullPointerException
	springtest.TestDAO.getDomains(TestDAO.java:15)</description>
		<content:encoded><![CDATA[<p>Im getting a null pointer exception:<br />
============================================<br />
//DAO<br />
public class TestDAO extends SimpleJdbcDaoSupport { </p>
<p>    public List&lt;Map&gt; getDomains() {<br />
        String query = &#034;select 1 from dual&#034;;<br />
        return getSimpleJdbcTemplate().queryForList(query);<br />
    }<br />
}<br />
============================================<br />
//Routing<br />
public class RoutingDataSource extends AbstractRoutingDataSource {<br />
    @Override<br />
    protected Object determineCurrentLookupKey() {<br />
        return SessionContextHolder.getDBServer();<br />
    }<br />
}<br />
============================================<br />
//controller<br />
@Controller<br />
@RequestMapping(value=&#034;/test&#034;)<br />
public class HandleRequest {</p>
<p>    @RequestMapping(method=RequestMethod.GET)<br />
    public String handle(Model model){</p>
<p>        TestDAO testDAO = new TestDAO();</p>
<p>        SessionContextHolder.setDBServer(&#034;server1&#034;);        </p>
<p>        List domains = testDAO.getDomains();</p>
<p>        model.addAttribute(&#034;domains&#034;, domains);<br />
        return &#034;test1&#034;;<br />
    }<br />
}<br />
============================================</p>
<p>	<!-- Scans the classpath of this application for @Components to deploy as beans --></p>
<p>	<!-- Configures the @Controller programming model --></p>
<p>	<!--  properties file --></p>
<p>============================================</p>
<p>And this is the error</p>
<p>java.lang.NullPointerException<br />
	springtest.TestDAO.getDomains(TestDAO.java:15)</p>
]]></content:encoded>
	</item>
</channel>
</rss>

