alibaba / druid

阿里云计算平台DataWorks(https://help.aliyun.com/document_detail/137663.html) 团队出品,为监控而生的数据库连接池
https://github.com/alibaba/druid/wiki
Apache License 2.0
27.98k stars 8.58k forks source link

多数据源配置加载失败 #2044

Open zhaohfup opened 7 years ago

zhaohfup commented 7 years ago

master 数据源配置

spring.datasource.druid.one.url=jdbc:mysql://localhost:3307/socks?useSSL=false&useUnicode=true&characterEncoding=utf8 spring.datasource.druid.one.username=root spring.datasource.druid.one.password=111111 spring.datasource.druid.one.driverClassName=com.mysql.jdbc.Driver

cluster 数据源配置

spring.datasource.druid.two.url=jdbc:mysql://localhost:3308/socks?useSSL=false&useUnicode=true&characterEncoding=utf8 spring.datasource.druid.two.username=root spring.datasource.druid.two.password=123456 spring.datasource.druid.two.driverClassName=com.mysql.jdbc.Driver

@Configuration @MapperScan(basePackages = "/scaffold/mastermapper", sqlSessionFactoryRef = "masterSqlSessionFactory") public class MybatisMasterConfiguer {

@Primary
@Bean(name = "masterDataSource")
@ConfigurationProperties(prefix = "spring.datasource.druid.one")
public DataSource masterDataSource() {
    return DruidDataSourceBuilder.create().build();
}

@Bean(name = "masterTransactionManager")
@Primary
public DataSourceTransactionManager masterTransactionManager() {
    return new DataSourceTransactionManager(masterDataSource());
}

@Bean(name = "masterSqlSessionFactory")
@Primary
public SqlSessionFactory masterSqlSessionFactory(@Qualifier("masterDataSource") DataSource masterDataSource)
        throws Exception {
    final SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
    sessionFactory.setDataSource(masterDataSource);
    return sessionFactory.getObject();
}

} 一直报这个错Cannot determine embedded database driver class for database type NONE exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: 能帮看下为什么吗?

yy1193889747 commented 6 years ago

参考这个看看https://github.com/yy1193889747/springboot-demo/tree/master/springboot-mybatis-thymeleaf