mybatis多数据源报错

时间:2022-03-28 05:36:21
2018-12-06 16:58:35,709 [ main ] - [ INFO  ] [ org.springframework.core.KotlinDetector : 57 ] -
Kotlin reflection implementation not found at runtime, related features won't be available. . ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.1.0.RELEASE) 2018-12-06 16:58:36,423 [ main ] - [ INFO ] [ cn.wanda.wedcredit.App : 50 ] -
Starting App on SH4010301061179 with PID 7528 (D:\tools\eclipse-jee-oxygen-2-win32-x86_64\eclipse\workspace\wedcredit\target\classes started by xdb in D:\tools\eclipse-jee-oxygen-2-win32-x86_64\eclipse\workspace\wedcredit)
2018-12-06 16:58:36,425 [ main ] - [ INFO ] [ cn.wanda.wedcredit.App : 675 ] -
No active profile set, falling back to default profiles: default
2018-12-06 16:58:36,688 [ background-preinit ] - [ WARN ] [ o.s.h.converter.json.Jackson2ObjectMapperBuilder : 122 ] -
For Jackson Kotlin classes support please add "com.fasterxml.jackson.module:jackson-module-kotlin" to the classpath
2018-12-06 16:58:39,260 [ main ] - [ INFO ] [ o.s.boot.web.embedded.tomcat.TomcatWebServer : 90 ] -
Tomcat initialized with port(s): 9901 (http)
2018-12-06 16:58:39,285 [ main ] - [ INFO ] [ org.apache.coyote.http11.Http11NioProtocol : 173 ] -
Initializing ProtocolHandler ["http-nio-9901"]
2018-12-06 16:58:39,314 [ main ] - [ INFO ] [ org.apache.catalina.core.StandardService : 173 ] -
Starting service [Tomcat]
2018-12-06 16:58:39,315 [ main ] - [ INFO ] [ org.apache.catalina.core.StandardEngine : 173 ] -
Starting Servlet Engine: Apache Tomcat/9.0.12
2018-12-06 16:58:39,334 [ main ] - [ INFO ] [ org.apache.catalina.core.AprLifecycleListener : 173 ] -
The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [C:\Program Files\Java\jdk1.8.0_162\bin;C:\windows\Sun\Java\bin;C:\windows\system32;C:\windows;C:/Program Files/Java/jre1.8.0_191/bin/server;C:/Program Files/Java/jre1.8.0_191/bin;C:/Program Files/Java/jre1.8.0_191/lib/amd64;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Program Files\Java\jdk1.8.0_162\bin;C:\ProgramData\Oracle\Java\javapath;d:\Oracle\ora90\bin;C:\windows\system32;C:\windows;C:\windows\System32\Wbem;C:\windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files\TortoiseSVN\bin;C:\Program Files\Git\cmd;D:\tools\apache-maven-3.5.3-bin\apache-maven-3.5.3\bin;D:\tools\gradle-4.7-bin\gradle-4.7\bin;D:\tools\android-sdk_r24.4.1-windows\android-sdk-windows\tools;D:\tools\android-sdk_r24.4.1-windows\android-sdk-windows\platform-tools;C:\Program Files\nodejs\;C:\Users\xdb\AppData\Local\Programs\Python\Python37\Scripts\;C:\Users\xdb\AppData\Local\Programs\Python\Python37\;C:\Users\xdb\AppData\Local\Programs\Fiddler;D:\tools\eclipse-jee-oxygen-2-win32-x86_64\eclipse;;.]
2018-12-06 16:58:39,674 [ main ] - [ INFO ] [ o.a.c.core.ContainerBase.[Tomcat].[localhost].[/] : 173 ] -
Initializing Spring embedded WebApplicationContext
2018-12-06 16:58:39,684 [ main ] - [ INFO ] [ org.springframework.web.context.ContextLoader : 285 ] -
Root WebApplicationContext: initialization completed in 3154 ms
2018-12-06 16:58:39,800 [ main ] - [ INFO ] [ o.s.boot.web.servlet.ServletRegistrationBean : 186 ] -
Servlet statViewServlet mapped to [/druid/*]
2018-12-06 16:58:39,803 [ main ] - [ INFO ] [ o.s.boot.web.servlet.ServletRegistrationBean : 186 ] -
Servlet dispatcherServlet mapped to [/]
2018-12-06 16:58:39,809 [ main ] - [ INFO ] [ o.s.boot.web.servlet.FilterRegistrationBean : 248 ] -
Mapping filter: 'characterEncodingFilter' to: [/*]
2018-12-06 16:58:39,810 [ main ] - [ INFO ] [ o.s.boot.web.servlet.FilterRegistrationBean : 248 ] -
Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2018-12-06 16:58:39,811 [ main ] - [ INFO ] [ o.s.boot.web.servlet.FilterRegistrationBean : 248 ] -
Mapping filter: 'formContentFilter' to: [/*]
2018-12-06 16:58:39,866 [ main ] - [ INFO ] [ o.s.boot.web.servlet.FilterRegistrationBean : 248 ] -
Mapping filter: 'requestContextFilter' to: [/*]
2018-12-06 16:58:39,867 [ main ] - [ INFO ] [ o.s.boot.web.servlet.FilterRegistrationBean : 261 ] -
Mapping filter: 'webStatFilter' to urls: [/*]
2018-12-06 16:58:40,744 [ main ] - [ INFO ] [ o.s.scheduling.concurrent.ThreadPoolTaskExecutor : 171 ] -
Initializing ExecutorService 'applicationTaskExecutor'
2018-12-06 16:58:40,967 [ main ] - [ WARN ] [ o.s.b.w.s.c.AnnotationConfigServletWebServerApplicationContext : 554 ] -
Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'sqlSessionTemplate' defined in class path resource [org/mybatis/spring/boot/autoconfigure/MybatisAutoConfiguration.class]: Unsatisfied dependency expressed through method 'sqlSessionTemplate' parameter 0; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 'org.apache.ibatis.session.SqlSessionFactory' available: expected single matching bean but found 2: creditSqlSessionFactory,wiseSqlSessionFactory
2018-12-06 16:58:40,969 [ main ] - [ INFO ] [ o.s.scheduling.concurrent.ThreadPoolTaskExecutor : 208 ] -
Shutting down ExecutorService 'applicationTaskExecutor'
2018-12-06 16:58:40,977 [ main ] - [ INFO ] [ org.apache.catalina.core.StandardService : 173 ] -
Stopping service [Tomcat]
2018-12-06 16:58:41,102 [ main ] - [ INFO ] [ o.s.b.a.l.ConditionEvaluationReportLoggingListener : 142 ] - Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2018-12-06 16:58:41,107 [ main ] - [ ERROR ] [ o.s.b.diagnostics.LoggingFailureAnalysisReporter : 42 ] - ***************************
APPLICATION FAILED TO START
*************************** Description: Parameter 0 of method sqlSessionTemplate in org.mybatis.spring.boot.autoconfigure.MybatisAutoConfiguration required a single bean, but 2 were found:
- creditSqlSessionFactory: defined by method 'sqlSessionFactory' in class path resource [cn/config/CreditDataSourcesConfig.class]
- wiseSqlSessionFactory: defined by method 'sessionFactory' in class path resource [cn/config/WiseDataSourcesConfig.class] Action: Consider marking one of the beans as @Primary, updating the consumer to accept multiple beans, or using @Qualifier to identify the bean that should be consumed

错误信息

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>cn.x</groupId>
<artifactId>xx</artifactId>
<version>0.0.1-SNAPSHOT</version> <parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.0.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties> <dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency> <dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.49</version>
</dependency> <dependency>
<groupId>com.caucho</groupId>
<artifactId>hessian</artifactId>
<version>3.1.6</version>
<type>jar</type>
<scope>system</scope>
<systemPath>${project.basedir}/lib/hessian-3.1.6.jar</systemPath>
</dependency>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0.4.0-atlassian-hosted</version>
<type>jar</type>
<scope>system</scope>
<systemPath>${project.basedir}/lib/ojdbc6-11.2.0.4.0-atlassian-hosted.jar</systemPath>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.49</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.1.12</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.12</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>3.12.0</version>
</dependency>
<dependency>
<groupId>com.squareup.okio</groupId>
<artifactId>okio</artifactId>
<version>2.1.0</version>
</dependency> </dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build> </project>

pom.xml

server:
port: 9901
aa:
url: http://qq.com/a
spring:
datasource1:
type: com.alibaba.druid.pool.DruidDataSource
url: jdbc:mysql://192.168.1.1:3306/aaa
username: root
password: root
datasource2:
type: com.alibaba.druid.pool.DruidDataSource
url: jdbc:oracle:thin:@//192.168.1.2:1530/bbb
username: root
password: root

application.yml

<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="false" scanPeriod="60 seconds"
debug="false">
<property name="LOG_HOME" value="./logs" />
<property name="appName" value="aaa" />
<appender name="stdout"
class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d [ %thread ] - [ %-5level ] [ %logger{50} : %line ] -
%msg%n</pattern>
</encoder>
</appender> <appender name="HTML" class="ch.qos.logback.core.FileAppender">
<file>${LOG_HOME}/${appName}.html</file>
<append>true</append>
<encoder
class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
<layout class="ch.qos.logback.classic.html.HTMLLayout">
<pattern>%d%thread%-5level%logger{50}%line%msg%n</pattern>
</layout>
<charset class="java.nio.charset.Charset">GBK</charset>
</encoder>
<immediateFlush>true</immediateFlush>
</appender> <appender name="appLogAppender"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOG_HOME}/${appName}.log</file>
<rollingPolicy
class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>${LOG_HOME}/${appName}-%d{yyyy-MM-dd}-%i.log
</fileNamePattern>
<maxFileSize>10MB</maxFileSize>
<maxHistory>30</maxHistory>
<totalSizeCap>300MB</totalSizeCap>
</rollingPolicy>
<encoder>
<pattern>%d [ %thread ] - [ %-5level ] [ %logger{50} : %line ] -
%msg%n</pattern>
<charset class="java.nio.charset.Charset">UTF-8</charset>
</encoder>
</appender> <appender name="appLogCurrent"
class="ch.qos.logback.core.FileAppender">
<file>${LOG_HOME}/${appName}_current.log</file>
<append>false</append>
<!-- set immediateFlush to false for much higher logging throughput -->
<immediateFlush>true</immediateFlush>
<!-- encoders are assigned the type ch.qos.logback.classic.encoder.PatternLayoutEncoder
by default -->
<encoder>
<pattern>%d [ %thread ] - [ %-5level ] [ %logger{35} : %line ] -
%msg%n</pattern>
</encoder>
</appender> <root level="info">
<appender-ref ref="stdout" />
<appender-ref ref="appLogAppender" />
<appender-ref ref="HTML" />
<appender-ref ref="appLogCurrent" />
</root>
</configuration>

logback.xml

package cn.wanda.wedcredit.config;

import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import com.alibaba.druid.support.http.StatViewServlet;
import com.alibaba.druid.support.http.WebStatFilter; @Configuration
public class DruidConfig { @Bean
public ServletRegistrationBean druidServlet() {
ServletRegistrationBean reg = new ServletRegistrationBean();
reg.setServlet(new StatViewServlet());
reg.addUrlMappings("/druid/*");
reg.addInitParameter("loginUsername", "admin");
reg.addInitParameter("loginPassword", "admin");
reg.addInitParameter("logSlowSql", "true");
return reg;
} @Bean
public FilterRegistrationBean filterRegistrationBean() {
FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();
filterRegistrationBean.setFilter(new WebStatFilter());
filterRegistrationBean.addUrlPatterns("/*");
filterRegistrationBean.addInitParameter("profileEnable", "true");
return filterRegistrationBean;
}
}

DruidConfig.java

package cn.wanda.wedcredit.config;

import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.SqlSessionTemplate;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.DataSourceTransactionManager; import com.alibaba.druid.pool.DruidDataSource; @Configuration
@MapperScan(basePackages = "cn.x.dao.credit", sqlSessionFactoryRef = "creditSqlSessionFactory")
public class CreditDataSourcesConfig {
@ConfigurationProperties("spring.datasource1")
@Bean(name = "creditDataSource")
public DruidDataSource druidDataSource() {
return new DruidDataSource();
} @Bean(name = "creditTransactionManager")
public DataSourceTransactionManager customTransactionManager() {
return new DataSourceTransactionManager(druidDataSource());
} @Bean(name = "creditSqlSessionFactory")
public SqlSessionFactory getSqlSessionFactory(@Qualifier("creditDataSource") DruidDataSource dataSource)
throws Exception {
final SqlSessionFactoryBean sessionFactoryBean = new SqlSessionFactoryBean();
// sessionFactoryBean.setConfigLocation(new
// ClassPathResource("mybatis-config.xml"));
sessionFactoryBean.setDataSource(dataSource);
return sessionFactoryBean.getObject();
} @Bean(name = "creditSqlSessionTemplate")
public SqlSessionTemplate getSqlSessionTemplate(@Qualifier("creditSqlSessionFactory") SqlSessionFactory sqlSessionFactory)
throws Exception {
return new SqlSessionTemplate(sqlSessionFactory);
}
}

DatasouceConfig1.java

package cn.wanda.wedcredit.config;

import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.SqlSessionTemplate;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.DataSourceTransactionManager; import com.alibaba.druid.pool.DruidDataSource; @Configuration
@MapperScan(basePackages = "cn.x.dao.wise", sqlSessionFactoryRef = "wiseSqlSessionFactory")
public class WiseDataSourcesConfig {
@ConfigurationProperties("spring.datasource2")
@Bean(name = "wiseDataSource")
public DruidDataSource druidDataSource() {
return new DruidDataSource();
} @Bean(name = "wiseTransactionManager")
public DataSourceTransactionManager customTransactionManager() {
return new DataSourceTransactionManager(druidDataSource());
} @Bean(name = "wiseSqlSessionFactory")
public SqlSessionFactory getSqlSessionFactory(@Qualifier("wiseDataSource") DruidDataSource dataSource)
throws Exception {
final SqlSessionFactoryBean sessionFactoryBean = new SqlSessionFactoryBean();
// sessionFactoryBean.setConfigLocation(new
// ClassPathResource("mybatis-config.xml"));
sessionFactoryBean.setDataSource(dataSource);
return sessionFactoryBean.getObject();
} @Bean(name = "wiseSqlSessionTemplate")
public SqlSessionTemplate getSqlSessionTemplate(@Qualifier("wiseSqlSessionFactory") SqlSessionFactory sqlSessionFactory)
throws Exception {
return new SqlSessionTemplate(sqlSessionFactory);
} }

DataSourceConfig2.java

mybatis多数据源报错的更多相关文章

  1. Loadrunner参数化连接oracle、mysql数据源报错及解决办法

    Loadrunner参数化连接oracle.mysql数据源报错及解决办法 (本人系统是Win7 64,  两位小伙伴因为是默认安装lr,安装在 最终参数化的时候,出现连接字符串无法自动加载出来: 最 ...

  2. Mybatis遇到的报错

    MyBatis遇到的报错: 1.Caused by: org.xml.sax.SAXParseException; lineNumber: 35; columnNumber: 17; 元素类型为 &q ...

  3. Mybatis调用存储过程报错

    Mybatis调用存储过程 贴码 123456 Error querying database. Cause: java.sql.SQLException: User does not have ac ...

  4. springboot整合mybatis的时候报错Caused by&colon; java&period;lang&period;IllegalArgumentException&colon; Property &&num;39&semi;sqlSessionFactory&&num;39&semi; or &&num;39&semi;sqlSessionTemplate&&num;39&semi; are required

    今天闲来无事,学习springboot整合mybatis,在bilibili看视频学的,视频中在dao层的interface上面加上org.apache.ibatis.annotations.Mapp ...

  5. mybatis读取配置文件报错:Could not find resource configuration&period;xml

    今天用idea编译mybatis的java项目时,一直报错,找不到config.xml 查看class文件夹,确实没有xml文件 也就是说,xml文件没在编译范围内 在pom.xml中,把xml文件加 ...

  6. mybatis批量插入报错

    报错内容 org.springframework.jdbc.UncategorizedSQLException: ### Error updating database. Cause: java.sq ...

  7. mybatis学习 -每天一记 mybatis insert null 报错

    mybatis 插入数据,model的属性存在null,插入报错 在使用mybatis 进行insert时,如果字段值存在null的情况,会出现插入失败的情况,解决方案: 如果使用spring boo ...

  8. mybatis批量更新报错badsql

    mybatis批量更新时语法写的都对,但是报错,需要在连接上面加上allowMultiQueries=true 示例:jdbc:MySQL://192.168.1.236:3306/test?useU ...

  9. 中间件weblogic控制台创建数据源报错---根据真实故事改编

    1.在weblogic控制台创建数据源,有报错--不能创建数据源,图免 2.weblogic数据源管理节点所在服务器telnet测试,到数据库1521端口是通的 3.经过请教各路大神,得出结论:由于子 ...

随机推荐

  1. 智能车学习(二十一)&mdash&semi;&mdash&semi;浅谈CCD交叉以及横线摆放

    一.CCD为何要交叉摆放?       首先使用横线摆放,CCD前瞻如果远一点,弯道丢线,再远一点直接窜道.所以需要很多很多代码的工作量,而且过弯的过程相当于没有任何的调节过程,就是一个偏差保持,或者 ...

  2. paper 90:人脸检测研究2015最新进展

    搜集整理了2004~2015性能最好的人脸检测的部分资料,欢迎交流和补充相关资料. 1:人脸检测性能 1.1 人脸检测测评 目前有两个比较大的人脸测评网站: 1:Face Detection Data ...

  3. SQL Server 脚本语句

    一.语法结构 select select_list [ into new_table ] from table_source [ where search_condition ] [ group by ...

  4. 【转】jQuery each函数中的continue及break

    continue :return true; break :return false; 也可以利用return即可跳出jQuery 来源:http://bie.xiaowangge.info/brow ...

  5. angular二级联动菜单

    <!doctype html> <html lang="en" ng-app='App'> <head> <meta charset=&q ...

  6. MVC 全局过滤器

    1. 新创建一个类 CheckLogin2. 在类中加入以下代码 public class CheckLogin : ActionFilterAttribute { public override v ...

  7. 浅谈JAVA中HashMap、ArrayList、StringBuilder等的扩容机制

    JAVA中的部分需要扩容的内容总结如下:第一部分: HashMap<String, String> hmap=new HashMap<>(); HashSet<Strin ...

  8. Hadoop常见错误问题及解决方法总结二

    问题导读:1.遇到问题该如何排除错误?2.看不到namenode的可能原因是什么?3.地址占用该如何解决?4.could only be replicatied to 0 nodes, instead ...

  9. select &plus; 回调 &plus; 事件循环

    #1. epoll并不代表一定比select好 # 在并发高的情况下,连接活跃度不是很高, epoll比select # 并发性不高,同时连接很活跃, select比epoll好 #通过非阻塞io实现 ...

  10. &period;net服务器端发起请求封装

    写一个静态类封装类似客户端的请求 public static class HttpHelper { #region Get public static string HttpGet(string ur ...