In order to improve the future of the site to expand the ability, I was using the data segmentation architecture, which requires my website to be flexible access to multiple databases, if it is direct operation of JDBC, this is not a problem. However, in SpringSide2.0, because of the integration of Hibernate, access to data is most often achieved through configuration.
The easiest way to use multiple databases in a SpringSide2.0 is to configure multiple sessionfactory, and here's my step.
First, to modify the Jdbc.properties file in the Src/resources/config directory, define the connections for multiple databases, as follows:
jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.urlYumDaysIndex=jdbc:mysql://localhost:3306/YumDaysIndex?useUnicode=true&characterEncoding=utf8
jdbc.urlYumDays001=jdbc:mysql://localhost:3306/YumDays001?useUnicode=true&characterEncoding=utf8
Then, modify the Dataaccesscontext-hibernate.xml file in the Src/resources/spring directory to define multiple data sources, which have only different URL attributes:
<!--data source definitions, use the Apache DBCP connection pool;
<bean id= "Datasourceyumdaysindex class=" Org.apache.commons.dbcp.BasicDataSource "destroy-method=" "Close"
<property name= "Driverclassname" value= "${jdbc.driverclassname}"/>
<property name= "url" value= "${jdbc.urlyumdaysindex}"/>
<property Name= "username" value= "${jdbc.username}"/>
<property name= "password" value= "${jdbc.password}"/>
</bean>
<!--data source definition, use Apache DBCP connection pool;
<bean id= "dataSourceYumDays001" class= "org.apache.co" Mmons.dbcp.BasicDataSource "destroy-method=" Close "
<property name=" Driverclassname "value=" ${ Jdbc.driverclassname} "/>
<property name=" url "value=" ${jdbc.urlyumdays001} "/>
<property Name = "username" value= "${jdbc.username}"/>
<property name= "password" value= "${jdbc.password}"/>
</ Bean>
Then, or modify the file, define multiple sessionfactory, which differ only by the properties of the data source:
<!--Hibernate sessionfatory-->
<bean id= "Sessionfactoryindex" class= " Org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean ">
<property name= "DataSource" ref= datasourceyumdaysindex "/>"
<property name= "annotatedclasses" >
<list>
<value>com.yumdays.model.Catalog</value>
<value>com.yumdays.model.Statistic</value>
</list>
</property>
<property name= "Hibernateproperties" >
<props>
<!--see/components/orm/hibernate/meta/dialect.properties for all dialect-->
<prop key= "Hibernate.dialect" >org.hibernate.dialect.MySQL5Dialect</prop>
<prop key= "Hibernate.show_sql" >true</prop>
<prop key= "Hibernate.cache.provider_class" >org.hibernate.cache.EhCacheProvider</prop>
<prop key= "Hibernate.cache.use_query_cache" >true</prop>
</props>
</property>
</bean>
<!--Hibernate sessionfatory-->
<bean id= "sessionFactory001" class= " Org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean ">
<property name= "DataSource" ref= dataSourceYumDays001 "/>"
<property name= "annotatedclasses" >
<list>
</list>
</property>
<property name= "Hibernateproperties" >
<props>
<!--see/components/orm/hibernate/meta/dialect.properties for all dialect-->
<prop key= "Hibernate.dialect" >org.hibernate.dialect.MySQL5Dialect</prop>
<prop key= "Hibernate.show_sql" >true</prop>
<prop key= "Hibernate.cache.provider_class" >org.hibernate.cache.EhCacheProvider</prop>
<prop key= "Hibernate.cache.use_query_cache" >true</prop>
</props>
</property>
</bean>