springbootについて+ MyBatisの設定し、複数のデータソースの問題のSQL文の失敗を印刷します
私たちは、統合MyBatisのをspringbootするときは、SQL文を印刷することができます
我々は、単一のデータ・ソースの場合は、統合MyBatisのをspringbootすると、次のことができます
#打印sql语句
mybatis.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl
我々は複数のデータソースを設定する場合でも、使用してmybatis.configuration.log-implには、SQL文を印刷しません
コンソールへの大活字情報
Creating a new SqlSession
SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@5c204c23] was not registered for synchronization because synchronization is not active
JDBC Connection [HikariProxyConnection@1363932663 wrapping com.mysql.cj.jdbc.ConnectionImpl@3f4319cd] will not be managed by Spring
Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@5c204c23]
理由:(mybatis.configuration.log-のimpl)のでtk.mybatis SqlSessionFactory何ら規定された時間がありませんSqlSessionFactoryを定義し、そして、我々は複数のデータソースを設定するとき、SqlSessionFactoryを再定義し、あなたは、SQL文を印刷したい場合は、したがって、我々はする必要がSqlSessionFactory構成し、複数のデータソース時に追加MybatisProperties。
あなたは解決するためにデータベースを構成する場合
MybatisPropertiesは、単に複数のデータソースの構成の設定を追加することができます
@Bean(name = "SecondarySessionFactory")
public SqlSessionFactory SecondarySessionFactory(@Qualifier("SecondaryDataSource") DataSource dataSource , MybatisProperties mybatisProperties) throws Exception {
SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
bean.setDataSource(dataSource);
bean.setConfiguration(mybatisProperties.getConfiguration());
return bean.getObject();
}