hap框架配置多数据源,后附自己的理解

hap官方文档地址;http://eco.hand-china.com/doc/hap/latest/dev_guide/01.getting_start/09_multi_data_source.html官方文档没有讲解hap默认配置,只是讲了怎么配置多数据源,对于我第一次配置的时候,不免遇到很多问题,下面是我对问题的描述跟解决方案添加配置文件Hap多数据源 是已mapper作为维度来...
摘要由CSDN通过智能技术生成

hap官方文档地址;http://eco.hand-china.com/doc/hap/latest/dev_guide/01.getting_start/09_multi_data_source.html
官方文档没有讲解hap默认配置,只是讲了怎么配置多数据源,对于我第一次配置的时候,不免遇到很多问题,下面是我对问题的描述跟解决方案

  1. 添加配置文件

Hap多数据源 是已mapper作为维度来配置的,即mapper下的方法都用一个数据源

hap默认配置单数据源,配置文件为applicationContext.xml文件,
故我们使用配置的时候,尽量避免用此文件名,否则会导致hap很多类都初始化加载不对,从而导致启动报错
我们可以看WEB-INF/classes/spring/applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
                           http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.xsd
                           http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd
                           http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd
                           http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd">

    <context:property-placeholder location="classpath:config.properties"/>

    <bean id="coreApplicationListener" class="com.hand.hap.core.ApplicationListenerBean"/>


    <!-- middleware datasource  com.hand.hap.core.JndiObjectFactoryBean-->
    <!-- jndi dataSource-->
    <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
        <property name="jndiName" value="${db.jndiName}"/>
    </bean>
    <!-- builtin datasource -->
    <!--<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">-->
    <!--<property name="driverClassName"-->
    <!--value="com.mysql.jdbc.Driver"/>-->
    <!--<property name="url" value="jdbc:mysql://127.0.0.1:3306/hap_dev"/>-->
    <!--<property name="username" value="hap_dev"/>-->
    <!--<property name="password" value="hap_dev"/>-->
    <!--</bean>-->

    <bean id="languageProvider" class="com.hand.hap.core.impl.LanguageProviderImpl"/>

    <bean id="messageSource" class="com.hand.hap.core.i18n.CacheMessageSource"/>

    <!-- config transactionManager -->
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource"/>
    </bean>

    <tx:annotation-driven transaction-manager="transactionManager"/>

    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <property name="mapperLocations" value="classpath*:/**/*Mapper.xml"/>
        <property name="plugins">
            <array>
                <bean class="com.hand.hap.core.interceptor.RequestContextInterceptor"/>
                <bean class="com.hand.hap.core.interceptor.MultiLanguageInterceptor"/>
                <bean class="com.hand.hap.core.interceptor.SecurityTokenInterceptor"/>
                <bean class="com.hand.hap.core.interceptor.OvnInterceptor"/>
          
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值