funky-eyes commented on issue #6731: URL: https://github.com/apache/incubator-seata/issues/6731#issuecomment-2270332927
> > 一个比较简单的方案,如果你是spring的应用, `DefaultCommonFenceHandler.get().setFenceHandler(new SpringFenceHandler());` 将上面的`SpringFenceHandler`包装后,用你的动态数据源处理后,再执行`SpringFenceHandler`的逻辑,或者你直接继承`SpringFenceHandler`进行处理动态数据源的逻辑 如果你不是spring的应用,你也可以通过这个api,自行扩展一个`FenceHandler`,再应用启动时第一时间进入`DefaultCommonFenceHandler`中 > > 如果您使用 Spring 应用程序,那么一个简单的方法: > > `DefaultCommonFenceHandler.get().setFenceHandler(new SpringFenceHandler());` 用动态数据源处理包装后`SpringFenceHandler`,继续执行 SpringFenceHandler 的逻辑。或者,您可以`SpringFenceHandler`直接扩展以合并动态数据源逻辑。 > > 对于不使用 Spring 的应用程序,您还可以通过独立扩展并在启动时`FenceHandler`将其放入来扩展此 API。`DefaultCommonFenceHandler` > > 我看到SpringFenceHandler是2.0版本的,我用的是1.7.1,用TCCFenceHandler可以么, 1.7.1版本能否提供个关键代码部分的demo,万分感谢! 项目是Springboot2.7的 > 1.7.1版本,我是每次都要TCCFenceHandler.setDataSource()和TCCFenceHandler.setTransactionTemplate()么 首先你自己创建一个TCCFenceHandler的子类的bean,seata侧就不会再构建TCCFenceHandler的bean,所以注入的是你的TCCFenceHandler,因为TCCFenceHandler是通过spring的DataSourceUtils获取的connection,只要你在这个之前,通过actionname能判断出来这个接口需要哪个数据源,或者通过commitMethod方法上的注解切换这个线程下的动态数据源的主数据源为哪个datasource就可以了,所以不需要每次都进行set之类的。 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
