You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by "iuhl (via GitHub)" <gi...@apache.org> on 2024/01/28 07:23:18 UTC
Re: [I] SpringCloud+Seata1.5.2+ShardingSphereJDBC5.2.1 SeataATShardingSphereTransactionManager.commit throw null exception [shardingsphere]
iuhl commented on issue #22356:
URL: https://github.com/apache/shardingsphere/issues/22356#issuecomment-1913484280
> > 重写 SeataTransactionHolder 类使其公开,添加一个拦截器并手动调用 SeataTransactionHolder.set(),它可以正常工作,但不知道是否正确。
> > ```java
> > public final class SeataTransactionHolder {
> >
> > private SeataTransactionHolder() {
> >
> > }
> >
> > private static final ThreadLocal<GlobalTransaction> CONTEXT = new ThreadLocal<>();
> >
> > /**
> > * Set seata global transaction.
> > *
> > * @param transaction global transaction context
> > */
> > public static void set(final GlobalTransaction transaction) {
> > CONTEXT.set(transaction);
> > }
> >
> > /**
> > * Get seata global transaction.
> > *
> > * @return global transaction
> > */
> > public static GlobalTransaction get() {
> > return CONTEXT.get();
> > }
> >
> > /**
> > * Clear global transaction.
> > */
> > public static void clear() {
> > CONTEXT.remove();
> > }
> > }
> > ```
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > ```java
> > @Configuration
> > public class SeataFeignInterceptorConfiguration implements WebMvcConfigurer {
> >
> > @Override
> > public void addInterceptors(InterceptorRegistry registry) {
> > registry.addInterceptor(new SeataFeignInterceptor()).addPathPatterns("/**");
> > }
> >
> > public static class SeataFeignInterceptor implements HandlerInterceptor {
> >
> > @Override
> > public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
> > String xid = RootContext.getXID();
> > if (xid == null) {
> > xid = request.getHeader(RootContext.KEY_XID);
> > }
> >
> > if (!StringUtils.isBlank(xid) && SeataTransactionHolder.get() == null) {
> > RootContext.bind(xid);
> > SeataTransactionHolder.set(GlobalTransactionContext.getCurrentOrCreate());
> > }
> >
> > return true;
> > }
> > }
> > }
> > ```
>
> 我们也以同样的方式解决了这个问题,但我们不知道是否会有其他影响
有在生产上检验过吗,我现在也打算这么去做了,我是在seata-dubbo拦截器里去做的,ApacheDubboTransactionPropagationFilter中加了
<img width="888" alt="image" src="https://github.com/apache/shardingsphere/assets/29973384/21b68254-05b1-45be-8a7e-cd2d2fd93b0a">
--
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: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org