springboot+mybatis-puls 使用多数据源,项目启动非常慢是为什么?

img



```java

started by Administrator in E:\dingding\demo(1))
2021-10-22 09:57:12.051  INFO 12352 --- [           main] c.e.datasource.demo.DemoApplication      : No active profile set, falling back to default profiles: default
2021-10-22 09:57:18.693  WARN 12352 --- [           main] o.m.s.mapper.ClassPathMapperScanner      : Skipping MapperFactoryBean with name 'assetInterestBonusDao' and 'com.example.datasource.demo.dao.ext.AssetInterestBonusDao' mapperInterface. Bean already defined with the same name!
2021-10-22 09:57:18.693  WARN 12352 --- [           main] o.m.s.mapper.ClassPathMapperScanner      : Skipping MapperFactoryBean with name 'assetInterestDao' and 'com.example.datasource.demo.dao.ext.AssetInterestDao' mapperInterface. Bean already defined with the same name!
2021-10-22 09:57:18.693  WARN 12352 --- [           main] o.m.s.mapper.ClassPathMapperScanner      : Skipping MapperFactoryBean with name 'assetPhysicBookValueDetailMapper' and 'com.example.datasource.demo.dao.ext.AssetPhysicBookValueDetailMapper' mapperInterface. Bean already defined with the same name!
2021-10-22 09:57:18.693  WARN 12352 --- [           main] o.m.s.mapper.ClassPathMapperScanner      : Skipping MapperFactoryBean with name 'assetPhysicBookValueMapper' and 'com.example.datasource.demo.dao.ext.AssetPhysicBookValueMapper' mapperInterface. Bean already defined with the same name!
2021-10-22 09:57:18.693  WARN 12352 --- [           main] o.m.s.mapper.ClassPathMapperScanner      : Skipping MapperFactoryBean with name 'assetPhysicMapper' and 'com.example.datasource.demo.dao.ext.AssetPhysicMapper' mapperInterface. Bean already defined with the same name!
2021-10-22 09:57:18.693  WARN 12352 --- [           main] o.m.s.mapper.ClassPathMapperScanner      : Skipping MapperFactoryBean with name 'contractLeaseMapper' and 'com.example.datasource.demo.dao.ext.ContractLeaseMapper' mapperInterface. Bean already defined with the same name!
2021-10-22 09:57:18.694  WARN 12352 --- [           main] o.m.s.mapper.ClassPathMapperScanner      : Skipping MapperFactoryBean with name 'contractLeaseReceivableDetailMapper' and 'com.example.datasource.demo.dao.ext.ContractLeaseReceivableDetailMapper' mapperInterface. Bean already defined with the same name!
2021-10-22 09:57:18.694  WARN 12352 --- [           main] o.m.s.mapper.ClassPathMapperScanner      : Skipping MapperFactoryBean with name 'contractLeaseReceivableMapper' and 'com.example.datasource.demo.dao.ext.ContractLeaseReceivableMapper' mapperInterface. Bean already defined with the same name!
2021-10-22 09:57:18.694  WARN 12352 --- [           main] o.m.s.mapper.ClassPathMapperScanner      : Skipping MapperFactoryBean with name 'contractMapper' and 'com.example.datasource.demo.dao.ext.ContractMapper' mapperInterface. Bean already defined with the same name!
2021-10-22 09:57:21.011  INFO 12352 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8333 (http)
2021-10-22 09:57:21.029  INFO 12352 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2021-10-22 09:57:21.029  INFO 12352 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.53]
2021-10-22 09:57:21.228  INFO 12352 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2021-10-22 09:57:21.229  INFO 12352 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 8509 ms
2021-10-22 09:57:21.717  INFO 12352 --- [           main] com.zaxxer.hikari.HikariDataSource       : db1 - Starting...
2021-10-22 09:57:22.071  INFO 12352 --- [           main] com.zaxxer.hikari.HikariDataSource       : db1 - Start completed.
2021-10-22 09:57:22.071  INFO 12352 --- [           main] com.zaxxer.hikari.HikariDataSource       : db2 - Starting...
2021-10-22 09:57:22.081  INFO 12352 --- [           main] com.zaxxer.hikari.HikariDataSource       : db2 - Start completed.
2021-10-22 09:57:22.081  INFO 12352 --- [           main] c.b.d.d.DynamicRoutingDataSource         : dynamic-datasource - load a datasource named [db2] success
2021-10-22 09:57:22.082  INFO 12352 --- [           main] c.b.d.d.DynamicRoutingDataSource         : dynamic-datasource - load a datasource named [db1] success
**2021-10-22 09:57:22.082  INFO 12352 --- [           main] c.b.d.d.DynamicRoutingDataSource         : dynamic-datasource initial loaded [2] datasource,primary datasource named [db1]
 _ _   |_  _ _|_. ___ _ |    _ 
| | |\/|_)(_| | |_\  |_)||_|_\ 
     /               |         
                        3.2.0 
2021-10-22 10:01:01.157**

```

项目启动慢,,不要赖mybatis-plus,有可能就是你项目本身的问题;

要先排查才知道的。

我用mybatis配置多个数据库,跟单个的差不多没什么影响

打印mybatis plus的地方在com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean.buildSqlSessionFactory,
这里输出没有时间,长耗时就在这前后,具体是前还是后,自己debug

img