毕业论文开发语言企业开发JAVA技术.NET技术WEB开发Linux/Unix数据库技术Windows平台移动平台嵌入式论文范文英语论文
您现在的位置: 毕业论文 >> java技术 >> 正文

Spring+Hibernate框架下Mysql读写分离、主从数据库配置无法选择数据源

更新时间:2012-11-20:  来源:毕业论文

 <context:annotation-config />             <!-- 自动加载SERVICE DAO ACTION -->      <context:component-scan base-package="com.test.dao.*" />       <context:component-scan base-package="com.test.service.*" />             <!-- 加载properties配置文件 -->      <bean id="propertyConfigurer"          class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">           <property name="locations">               <list>                   <value>classpath:log4j.properties</value>                   <value>classpath:jdbc.properties</value>               </list>           </property>       </bean>           <bean id="parentDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">           <property name="initialPoolSize"><value>30</value></property>         <property name="minPoolSize"><value>10</value></property>         <property name="maxPoolSize"><value>50</value></property>     </bean>        <!-- 主数据源-->      <bean id="masterDataSource" parent="parentDataSource">           <property name="driverClass" value="com.mysql.jdbc.Driver" />           <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/test" />           <property name="user" value="root" />           <property name="password" value="" />       </bean>                 <!-- 从数据源-->      <bean id="slaveDataSource" parent="parentDataSource">           <property name="driverClass" value="com.mysql.jdbc.Driver" />           <property name="jdbcUrl" value="jdbc:mysql://localhost:3307/test" />           <property name="user" value="root" />           <property name="password" value="" />      </bean>           <bean id="dataSource" class="com.test.datasource.DynamicDataSource">           <property name="targetDataSources">               <map key-type="java.lang.String">                   <entry key="slave" value-ref="slaveDataSource" />                 <entry key="master" value-ref="masterDataSource" />               </map>           </property>           <property name="defaultTargetDataSource" ref="masterDataSource" />       </bean>           <!-- 配置sessionFactory -->      <bean id="sessionFactory"          class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">           <property name="dataSource"><ref local="dataSource"/></property>          <property name="packagesToScan" value="com.test.bean" />          <property name="configLocation" value="classpath:hibernate.cfg.xml">         </property>         <property name="hibernateProperties">               <props>                   <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>                  <prop key="hibernate.show_sql">true</prop>                  <prop key="hibernate.format_sql">true</prop>              </props>           </property>       </bean>               <!-- 切换数据源 -->      <bean id="dataSourceAdvice" class="com.test.datasource.aop.DataSourceAdvice"></bean>             <aop:config>           <aop:pointcut id="businessService" expression="execution(* com.test.service..*.*(..))" />         <aop:advisor  pointcut-ref="businessService" advice-ref="dataSourceAdvice" />     </aop:config>             <!-- 配置事务管理器 -->      <bean id="transactionManager"          class="org.springframework.orm.hibernate3.HibernateTransactionManager">           <property name="sessionFactory">               <ref bean="sessionFactory" />           </property>       </bean>             <!--配置事务的传播特性 -->      <tx:advice id="txAdvice" transaction-manager="transactionManager">           <tx:attributes>               <!-- 对增、删、改方法进行事务支持 -->              <tx:method name="add*" propagation="REQUIRED" />               <tx:method name="create*" propagation="REQUIRED" />               <tx:method name="save*" propagation="REQUIRED" />               <tx:method name="edit*" propagation="REQUIRED" />               <tx:method name="update*" propagation="REQUIRED" />               <tx:method name="delete*" propagation="REQUIRED" />               <tx:method name="remove*" propagation="REQUIRED" />               <!-- 对查找方法进行只读事务 -->              <tx:method name="loadByUsername*" propagation="SUPPORTS" read-only="true" />               <!-- 对其它方法进行只读事务 -->              <tx:method name="*" propagation="SUPPORTS" read-only="true" />           </tx:attributes>       </tx:advice>             <!--那些类的哪些方法参与事务 -->      <aop:config>           <aop:advisor              pointcut="execution(* com.test.service..*.*(..))"              advice-ref="txAdvice" />       </aop:config>            <!-- 配置DAO -->    <bean id="personDAO" class="com.test.dao.impl.PersonDAOImpl">         <property name="sessionFactory">             <ref local="sessionFactory"></ref>         </property>     </bean>           <!-- 配置service -->    <bean id="personService" class="com.test.service.impl.PersonServiceImpl">         <property name="personDAO">             <ref bean="personDAO"></ref>         </property>     </bean> </beans>

我想在调用service层时,先执行com.test.datasource.aop.DataSourceAdvice(implements MethodBeforeAdvice,AfterReturningAdvice, ThrowsAdvice)类中的berfore方法,不知道为什么执行不了。

要执行的那个类有没有加上@Component注解?

设为首页 | 联系站长 | 友情链接 | 网站地图 |

copyright©youerw.com 优尔论文网 严禁转载
如果本毕业论文网损害了您的利益或者侵犯了您的权利,请及时联系,我们一定会及时改正。