SpringBoot 自定义注解 实现多数据源( 二 )

Service

SpringBoot 自定义注解 实现多数据源

文章插图
启动测试类:
import look.word.datasource.service.BookService;import org.junit.jupiter.api.Test;import org.springframework.boot.test.context.SpringBootTest;import javax.annotation.Resource;/** * @author : look-word * 2022-10-10 23:11 **/@SpringBootTestpublic class TestBookMapper {@Resourceprivate BookService bookService;@Testvoid updatePrice() {System.out.println(bookService.updatePrice(1, 777));}}
观察执行日志可知,数据源的切换实现了,事务也没有失效 。

SpringBoot 自定义注解 实现多数据源

文章插图
参考文章:
  • https://blog.csdn.net/Wu_Shang001/article/details/121182437
  • https://blog.csdn.net/qq_45515182/article/details/126330084

经验总结扩展阅读