mybatis多数据源报错
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多数据源报错的更多相关文章
- Loadrunner参数化连接oracle、mysql数据源报错及解决办法
Loadrunner参数化连接oracle.mysql数据源报错及解决办法 (本人系统是Win7 64, 两位小伙伴因为是默认安装lr,安装在 最终参数化的时候,出现连接字符串无法自动加载出来: 最 ...
- Mybatis遇到的报错
MyBatis遇到的报错: 1.Caused by: org.xml.sax.SAXParseException; lineNumber: 35; columnNumber: 17; 元素类型为 &q ...
- Mybatis调用存储过程报错
Mybatis调用存储过程 贴码 123456 Error querying database. Cause: java.sql.SQLException: User does not have ac ...
- springboot整合mybatis的时候报错Caused by: java.lang.IllegalArgumentException: Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required
今天闲来无事,学习springboot整合mybatis,在bilibili看视频学的,视频中在dao层的interface上面加上org.apache.ibatis.annotations.Mapp ...
- mybatis读取配置文件报错:Could not find resource configuration.xml
今天用idea编译mybatis的java项目时,一直报错,找不到config.xml 查看class文件夹,确实没有xml文件 也就是说,xml文件没在编译范围内 在pom.xml中,把xml文件加 ...
- mybatis批量插入报错
报错内容 org.springframework.jdbc.UncategorizedSQLException: ### Error updating database. Cause: java.sq ...
- mybatis学习 -每天一记 mybatis insert null 报错
mybatis 插入数据,model的属性存在null,插入报错 在使用mybatis 进行insert时,如果字段值存在null的情况,会出现插入失败的情况,解决方案: 如果使用spring boo ...
- mybatis批量更新报错badsql
mybatis批量更新时语法写的都对,但是报错,需要在连接上面加上allowMultiQueries=true 示例:jdbc:MySQL://192.168.1.236:3306/test?useU ...
- 中间件weblogic控制台创建数据源报错---根据真实故事改编
1.在weblogic控制台创建数据源,有报错--不能创建数据源,图免 2.weblogic数据源管理节点所在服务器telnet测试,到数据库1521端口是通的 3.经过请教各路大神,得出结论:由于子 ...
随机推荐
- MailUtils类:用于发送激活邮件
该类用于发送激活邮件 package com.itheima.utils; import java.util.Properties; import javax.mail.Authenticator; ...
- Nginx 模块分类
L:34
- 弹出层-layui
type 0(信息框,默认)1(页面层)2(iframe层)3(加载层)4(tips层) 弹出层 //winIndex存储弹出层的index,以便关闭弹出层时使用 function openWindo ...
- HTML条件注释
前面的话 IE条件注释是微软从IE5开始就提供的一种非标准逻辑语句,作用是可以灵活的为不同IE版本浏览器导入不同html元素.很显然这种方法的最大好处就在于属于微软官方给出的兼容解决办法而且还能通过W ...
- Go指针相关
结合这个例子分析一下 结果: 结合以往C语言的基础,画了一张图来解释为什么会有上面这些值的出现.先查看下Go中的这两个运算符是啥吧. ①对于所有带a的结果 var a int = 1 定义了一个变量a ...
- Cetos 7 防火墙设置
1.关闭防火墙: # systemctl stop firewalld.service 2.开启防火墙: # systemctl start firewalld.service 3.关闭开机启动: # ...
- P2084 进制转换
原题链接 https://www.luogu.org/problemnew/show/P2084 这个题的思路就是先将输入的数字存到字符数组里,然后求出这一串数字中的非0元素的个数total,并记录最 ...
- 洛谷3705 [SDOI2017] 新生舞会 【01分数规划】【KM算法】
题目分析: 裸题.怀疑$ O(n^4log{n}) $跑不过,考虑Edmonds-Karp优化. 代码: #include<bits/stdc++.h> using namespace s ...
- Java 枚举 的学习
在JDK5.0之后,引进了一种与C语言相通的枚举类型. 所谓枚举类型就是指含有一组具有固定值, 并且容量有限的数据集合. 例如,定义一个星期的枚举类型, 从周一到周日是具有固定大小和固定值的集合 pu ...
- 【COGS2652】秘术「天文密葬法」(长链剖分,分数规划)
[COGS2652]秘术「天文密葬法」(长链剖分,分数规划) 题面 Cogs 上面废话真多,建议直接拉到最下面看一句话题意吧: 给个树,第i个点有两个权值ai和bi,现在求一条长度为m的路径,使得Σa ...