SpringMvc项目applicationContext.xml中关于数据源的配置,有什么好方案可以多数据源切换?
如A服务器用数据源1,B服务器用数据源2.<beanid="dataSource"class="com.mchange.v2.c3p0.ComboPooledDataSo...
如A服务器用数据源1,B服务器用数据源2.
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close"
p:driverClass="com.mysql.jdbc.Driver"
p:jdbcUrl="jdbc:mysql://localjost:3306/rongtest?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull"
p:user="root"
p:password="123456"
p:testConnectionOnCheckin="true"
p:automaticTestTable="C3P0TestTable"
p:idleConnectionTestPeriod="700"
p:maxIdleTime="450"
/> 展开
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close"
p:driverClass="com.mysql.jdbc.Driver"
p:jdbcUrl="jdbc:mysql://localjost:3306/rongtest?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull"
p:user="root"
p:password="123456"
p:testConnectionOnCheckin="true"
p:automaticTestTable="C3P0TestTable"
p:idleConnectionTestPeriod="700"
p:maxIdleTime="450"
/> 展开
展开全部
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
<!-- <mvc:annotation-driven /> <context:component-scan base-package="jww.demo.controller*">
</context:component-scan> -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName">
<value>org.gjt.mm.mysql.Driver</value>
</property>
<property name="url">
<value>jdbc:mysql://localhost:3306/computer</value>
</property>
<property name="username">
<value>root</value>
</property>
<property name="password">
<value>mysqladmin</value>
</property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource">
</property>
<property name="mappingResources">
<list>
<value>jww/entity/User.hbm.xml</value>
<value>jww/entity/Computer.hbm.xml</value>
<value>jww/entity/Commentary.hbm.xml</value>
<value>jww/entity/BeginTime.hbm.xml</value>
<value>jww/entity/EndTime.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>
<!-- <bean id="personDaoImp" class="jww.demo.dao.imp.PersonDAOImp"> <property
name="sessionFactory" ref="sessionFactory"></property> </bean> <bean id="personService"
class="jww.demo.service.PersonService"> <property name="personDAOImp" ref="personDaoImp"></property>
</bean> -->
<bean id="hibernateUtil" class="jww.entity.HibernateUtil">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
[html] view plaincopy
<!--具体实现类的注入-->
<!-- 电脑详情 -->
<bean id="computerDao" class="jww.dao.ComputerDAO"></bean>
<bean id="computerService" class="jww.service.ComputerService">
<property name="computerDao" ref="computerDao"></property>
</bean>
<!-- 用户登录 -->
<bean id="userDao" class="jww.dao.UserDAO"></bean>
<bean id="userService" class="jww.service.UserService">
<property name="userDao" ref="userDao"></property>
</bean>
[html] view plaincopy
</beans>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
<!-- <mvc:annotation-driven /> <context:component-scan base-package="jww.demo.controller*">
</context:component-scan> -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName">
<value>org.gjt.mm.mysql.Driver</value>
</property>
<property name="url">
<value>jdbc:mysql://localhost:3306/computer</value>
</property>
<property name="username">
<value>root</value>
</property>
<property name="password">
<value>mysqladmin</value>
</property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource">
</property>
<property name="mappingResources">
<list>
<value>jww/entity/User.hbm.xml</value>
<value>jww/entity/Computer.hbm.xml</value>
<value>jww/entity/Commentary.hbm.xml</value>
<value>jww/entity/BeginTime.hbm.xml</value>
<value>jww/entity/EndTime.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>
<!-- <bean id="personDaoImp" class="jww.demo.dao.imp.PersonDAOImp"> <property
name="sessionFactory" ref="sessionFactory"></property> </bean> <bean id="personService"
class="jww.demo.service.PersonService"> <property name="personDAOImp" ref="personDaoImp"></property>
</bean> -->
<bean id="hibernateUtil" class="jww.entity.HibernateUtil">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
[html] view plaincopy
<!--具体实现类的注入-->
<!-- 电脑详情 -->
<bean id="computerDao" class="jww.dao.ComputerDAO"></bean>
<bean id="computerService" class="jww.service.ComputerService">
<property name="computerDao" ref="computerDao"></property>
</bean>
<!-- 用户登录 -->
<bean id="userDao" class="jww.dao.UserDAO"></bean>
<bean id="userService" class="jww.service.UserService">
<property name="userDao" ref="userDao"></property>
</bean>
[html] view plaincopy
</beans>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询