huangxiuqi commented on issue #22356:
URL:
https://github.com/apache/shardingsphere/issues/22356#issuecomment-1325849379
Rewrite the SeataTransactionHolder class to make it public, add an
interceptor and manually call SeataTransactionHolder.set(), it can work
normally, but I don't know if it is correct.
```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;
}
}
}
```
--
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]