WebFlux同时支持Mysql+MongdoDb两种数据库
继续上一篇文章,目前我遇到一个需求,WebFlux需要同时支持Mysql和MongoDb两种数据库。而大部分博文都只说了一种。按照博文中集成后,服务启动就会报错。下面给大家讲解,如何解决这个问题。
这个问题处理很简单,就算在Repository上实现不同的接口
第一步
首先是Mongdo的接口。
@Repository public interface StudentRepository extends ReactiveMongoRepository{ }
第二步
然后就是Mysql的接口。
@Repository public interface StudentRepository extends R2dbcRepository{ }
然后启动就可以正常启动了。
另外讲maven的依赖列出来~
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-r2dbc</artifactId>
</dependency>
<dependency>
<groupId>dev.miku</groupId>
<artifactId>r2dbc-mysql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb-reactive</artifactId>
</dependency>