Caused by: java.lang.RuntimeException: org.springframework.transaction.CannotCreateTransactionException: Could not open JDBC Connection for transaction; nested exception is com.baomidou.dynamic.datasource.exception.CannotFindDataSourceException: dynamic-datasource can not find primary datasource
Could not open JDBC Connection for transaction; nested exception is com.baomidou.dynamic.datasource.exception.CannotFindDataSourceException: dynamic-datasource can not find primary datasource
原因:
引用了dynamic-datasource-spring-boot-starter,在service层使用了@Transaction注解,但是没有在service层使用@DS选择数据库
解决方案:
方案一、去除@Transaction注解
方案二、设置primary数据库
方案三、在Service层加入@DS注解选择数据库