springboot+mybatisplus 配置多数据源打印sql语句失效的问题

目录

1.如果没有配置多数据源 下打印sql ,只在yml里面配置就会报如下的信息

2.这里说一下解决方法两种方式 都是在多数据源配置文件下 加入代码解决 


1.如果没有配置多数据源 下打印sql ,只在yml里面配置就会报如下的信息

Creating a new SqlSession
SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@17c40f6] was not registered for synchronization because synchronization is not active

mybatis-plus:
  configuration:
    call-setters-on-nulls: on
    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl

2.这里说一下解决方法两种方式 都是在多数据源配置文件下 加入代码解决 

1.mybatisplus 多数据源配置文件下加入

        MybatisConfiguration configuration = new MybatisConfiguration();
        configuration.setMapUnderscoreToCamelCase(true);
        configuration.setCacheEnabled(false);
        // 配置打印sql语句s
        configuration.setLogImpl(StdOutImpl.class);
        bean.setConfiguration(configuration);

 2.第二种方式 比较简单 首先在方法参数里面加入  MybatisPlusProperties mybatisPlusProperties,然后在代码里面加入 

bean.setConfiguration(mybatisPlusProperties.getConfiguration());
    @Primary
    @Bean(name = "SqlSessionFactory1")
    public SqlSessionFactory testSqlSessionFactory(@Qualifier("DataSource1") DataSource dataSource, MybatisPlusProperties mybatisPlusProperties) throws Exception {
        MybatisSqlSessionFactoryBean bean = new MybatisSqlSessionFactoryBean();
        bean.setDataSource(dataSource);
//        MybatisConfiguration configuration = new MybatisConfiguration();
//        configuration.setMapUnderscoreToCamelCase(true);
//        configuration.setCacheEnabled(false);
 配置打印sql语句s
//        configuration.setLogImpl(StdOutImpl.class);
//        bean.setConfiguration(configuration);
        bean.setConfiguration(mybatisPlusProperties.getConfiguration());
        bean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:mapper/chassis_mapper/*.xml"));
        return bean.getObject();
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值