修改代码,去除apollo、security和seata配置,替换为nacos
This commit is contained in:
@ -3,8 +3,6 @@ package com.chinaunicom.mall.ebtp.core;
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
|
||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
|
||||
@MapperScan({"com.chinaunicom.mall.ebtp.core.**.dao"})
|
||||
|
@ -1,20 +0,0 @@
|
||||
package com.chinaunicom.mall.ebtp.core.config;
|
||||
|
||||
import com.chinaunicom.mall.ebtp.common.config.FeignConfig;
|
||||
import feign.RequestTemplate;
|
||||
import io.seata.core.context.RootContext;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
public class FeignSeataConfig extends FeignConfig {
|
||||
|
||||
@Override
|
||||
public void apply(RequestTemplate template) {
|
||||
String xid = RootContext.getXID();
|
||||
if (StringUtils.isNotEmpty(xid)) {
|
||||
template.header(RootContext.KEY_XID, xid);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,74 +0,0 @@
|
||||
package com.chinaunicom.mall.ebtp.core.config;
|
||||
|
||||
import cn.hutool.core.exceptions.ExceptionUtil;
|
||||
import com.chinaunicom.mall.ebtp.common.base.entity.BaseResponse;
|
||||
import io.seata.core.context.RootContext;
|
||||
import io.seata.core.exception.RmTransactionException;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.transaction.TransactionSystemException;
|
||||
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 异常处理 拦截BindException异常,返回HttpStatus是400的绑定错误信息
|
||||
* 拦截FrameException异常,返回HttpStatus是406的业务处理错误信息(支持自定义状态码)
|
||||
* 拦截Exception异常,返回HttpStatus是500服务器内部异常
|
||||
*
|
||||
* @author fqj
|
||||
* @date 2020年9月3日 11:42:25
|
||||
*/
|
||||
@Slf4j
|
||||
@ControllerAdvice
|
||||
@Order(1)
|
||||
@ResponseBody
|
||||
@ConditionalOnProperty(name = "mconfig.io.seata.core.exception-handle-enabled", matchIfMissing = true)
|
||||
public class SeataExceptionHandlerAdvice {
|
||||
|
||||
@ExceptionHandler({TransactionSystemException.class, RmTransactionException.class})
|
||||
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
||||
public BaseResponse<String> handleTransactionSystemException(HttpServletRequest request,
|
||||
TransactionSystemException exception) {
|
||||
log.info(ExceptionUtil.stacktraceToString(exception));
|
||||
if (((String) Objects.requireNonNull(exception.getMessage())).contains("may be has finished")) {
|
||||
String xid = RootContext.getXID();
|
||||
if (StringUtils.isNotEmpty(xid)) {
|
||||
RootContext.unbind();
|
||||
log.info("TransactionSystemException ----- suspending current transaction,xid = {}", xid);
|
||||
|
||||
return BaseResponse.fail("系统繁忙,请重试", null);
|
||||
}
|
||||
}
|
||||
return BaseResponse.fail("系统异常", exception.getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* 参数异常
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
class ArgumentInvalidResult {
|
||||
/**
|
||||
* 字段名
|
||||
*/
|
||||
private String field;
|
||||
/**
|
||||
* 输入的错误值
|
||||
*/
|
||||
private Object rejectedValue;
|
||||
/**
|
||||
* 错误信息
|
||||
*/
|
||||
private String defaultMessage;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user