Can you use English? ------------------
Liang Zhang (John) Apache ShardingSphere & Dubbo [email protected] <[email protected]> 于2020年2月28日周五 下午7:21写道: > 您好,我通过命名空间引用sharding,一致报下面这个错误: > 2020-02-28 > 15:49:18.884|ywwl-alarm-api|ERROR|o.s.boot.diagnostics.LoggingFailureAnalysisReporter.report:42| > > *************************** > APPLICATION FAILED TO START > *************************** > > Description: > > file > [D:\workspace\alarm-api\alarm-api-dal\target\classes\com\ywwl\alarm\api\dal\dao\BusinessAlarmConfigMapper.class] > required a single bean, but 2 were found: > - dataSource0: defined in file > [D:\workspace\alarm-api\alarm-api-web\target\classes\spring\spring-mybatis.xml] > - shardingDataSource: defined in null > > 我的配置如下: > <?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:tx="http://www.springframework.org/schema/tx" > xmlns:sharding=" > http://shardingsphere.apache.org/schema/shardingsphere/sharding" > xsi:schemaLocation="http://www.springframework.org/schema/beans > http://www.springframework.org/schema/beans/spring-beans.xsd > http://www.springframework.org/schema/tx > http://www.springframework.org/schema/tx/spring-tx.xsd > http://shardingsphere.apache.org/schema/shardingsphere/sharding > > http://shardingsphere.apache.org/schema/shardingsphere/sharding/sharding.xsd > "> > > <bean id="dBSelfPwdCallback" > class="com.ywwl.alarm.api.dal.common.DBSelfPwdCallback" lazy-init="true"/> > > <!-- 配置数据源 --> > <bean id="dataSource0" class="com.alibaba.druid.pool.DruidDataSource" > destroy-method="close"> > <property name="driverClassName" value="${driver}" /> > <property name="url" value="${url}" /> > <property name="username" value="${username}" /> > <property name="password" value="${password}" /> > > <!-- 初始化连接大小 --> > <property name="initialSize" value="${initialSize}"></property> > <!-- 连接池最大数量 --> > <property name="maxActive" value="${maxActive}"></property> > <!-- 连接池最大空闲 maxIdle参数已经被弃用 > <property name="maxIdle" value="${maxIdle}"></property>--> > <!-- 连接池最小空闲 --> > <property name="minIdle" value="${minIdle}"></property> > <!-- 获取连接最大等待时间 --> > <property name="maxWait" value="${maxWait}"></property> > <!-- 超过时间限制是否回收 --> > <!--<property name="removeAbandoned" value="${removeAbandoned}" > />--> > <!-- 超过时间限制多长; --> > <property name="removeAbandonedTimeout" > value="${removeAbandonedTimeout}" /> > <!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 --> > <property name="timeBetweenEvictionRunsMillis" > value="${timeBetweenEvictionRunsMillis}" /> > <!-- 配置一个连接在池中最小生存的时间,单位是毫秒 --> > <property name="minEvictableIdleTimeMillis" > value="${minEvictableIdleTimeMillis}" /> > <!-- 用来检测连接是否有效的sql,要求是一个查询语句--> > <!-- <property name="validationQuery" value="${validationQuery}" > /> --> > <!-- 申请连接的时候检测 --> > <!--<property name="testWhileIdle" value="${testWhileIdle}" /> --> > <!-- 申请连接时执行validationQuery检测连接是否有效,配置为true会降低性能 --> > <!--<property name="testOnBorrow" value="${testOnBorrow}" /> --> > <!-- 归还连接时执行validationQuery检测连接是否有效,配置为true会降低性能 --> > <!--<property name="testOnReturn" value="${testOnReturn}" /> --> > <!-- 打开PSCache,并且指定每个连接上PSCache的大小 --> > <!--<property name="poolPreparedStatements" > value="${poolPreparedStatements}" /> --> > <property name="maxPoolPreparedStatementPerConnectionSize" > value="${maxPoolPreparedStatementPerConnectionSize}" /> > <!--属性类型是字符串,通过别名的方式配置扩展插件,常用的插件有: > 监控统计用的filter:stat > 日志用的filter:log4j > 防御SQL注入的filter:wall --> > > <!-- > <property name="filters" value="${filters}" /> > --> > <property name="passwordCallback" ref="dBSelfPwdCallback"/> > <property name="connectionInitSqls" value="set names utf8mb4;"/> > <property name="connectionProperties" > value="config.decrypt=${druid.config.decrypt};config.decrypt.key=${druid.config.decrypt.publicKey};password=${password}" > /> > > > <!-- 关闭abanded连接时输出错误日志 --> > <property name="logAbandoned" value="true"/> > > <!-- 监控数据库 --> > <property name="filters" value="mergeStat"/> > <!--手动提交--> > <property name="defaultAutoCommit" value="${defaultAutoCommit}"/> > </bean> > > > <!-- 配置分表算法 --> > <bean id="shardingAlgorithm" > class="com.ywwl.alarm.api.sharding.ShardingAlgorithm" /> > <sharding:standard-strategy id="orderTableStrategy" > sharding-column="root_time" precise-algorithm-ref="shardingAlgorithm" /> > > <sharding:data-source id="shardingDataSource"> > <sharding:sharding-rule data-source-names="dataSource0" > default-data-source-name="dataSource0"> > <sharding:table-rules> > <sharding:table-rule logic-table="business_monitor_log" > table-strategy-ref="orderTableStrategy" /> > </sharding:table-rules> > <sharding:binding-table-rules> > <sharding:binding-table-rule > logic-tables="business_monitor_log"/> > </sharding:binding-table-rules> > </sharding:sharding-rule> > </sharding:data-source> > > <!-- Spring整合Mybatis,更多查看文档:http://mp.baomidou.com --> > <bean id="sqlSessionFactory" > class="com.baomidou.mybatisplus.spring.MybatisSqlSessionFactoryBean"> > <property name="dataSource" ref="shardingDataSource"/> > <!-- 自动扫描Mapping.xml文件 --> > <property name="mapperLocations" value="classpath:mapper/*.xml"/> > > <!-- 配置 Mybatis 配置文件(可无) --> > <property name="configLocation" > value="classpath:mybatis/mybatis-config.xml"/> > <!-- 切换一种方式,不配置configLocation --> > <property name="configurationProperties"> > <props> > <prop key="cacheEnabled">true</prop> > <prop key="callSettersOnNulls">true</prop> > </props> > </property> > > <!-- 配置包别名 --> > <property name="typeAliasesPackage" > value="com.ywwl.api.demo.api.dal.po"/> > <property name="plugins"> > <array> > <!-- 分页插件配置 --> > <bean id="paginationInterceptor" > class="com.baomidou.mybatisplus.plugins.PaginationInterceptor"> > <property name="dialectType" value="mysql"/> > </bean> > </array> > </property> > <!-- 全局配置注入 --> > <property name="globalConfig" ref="globalConfig" /> > </bean> > > <!-- 定义 MP 全局策略 --> > <bean id="globalConfig" > class="com.baomidou.mybatisplus.entity.GlobalConfiguration"> > <!-- > AUTO->`0`("数据库ID自增") > INPUT->`1`(用户输入ID") > ID_WORKER->`2`("全局唯一ID") > UUID->`3`("全局唯一ID") > --> > <property name="idType" value="0" /> > <!-- > MYSQL->`mysql` > ORACLE->`oracle` > DB2->`db2` > H2->`h2` > HSQL->`hsql` > SQLITE->`sqlite` > POSTGRE->`postgresql` > SQLSERVER2005->`sqlserver2005` > SQLSERVER->`sqlserver` > --> > <property name="dbType" value="mysql"/> > > <!-- Oracle需要添加该项 --> > <!-- <property name="dbType" value="oracle" /> --> > > <!-- 全局表为下划线命名设置 true --> > <property name="dbColumnUnderline" value="true" /> > </bean> > > <!-- MyBatis 动态扫描 --> > <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> > <property name="basePackage" > value="com.ywwl.api.demo.api.dal.dao"/> > </bean> > > <!-- 配置事务管理 --> > <bean name="transactionManager" > class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> > <property name="dataSource" ref="shardingDataSource"/> > </bean> > > <tx:annotation-driven transaction-manager="transactionManager"/> > > </beans> > > 使用的mybatieplus插件。希望能得到你们答案。谢谢 > > > >
