Commit 913c9dc5 by 李秋伟

Merge branch 'dev' into 'master'

Dev

See merge request mall/arch/matrix!23
parents 2f91c2a8 fb55803a
...@@ -63,6 +63,10 @@ ...@@ -63,6 +63,10 @@
<scope>provided</scope> <scope>provided</scope>
<optional>true</optional> <optional>true</optional>
</dependency> </dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
</dependencies> </dependencies>
......
...@@ -41,7 +41,7 @@ public class WebUtil { ...@@ -41,7 +41,7 @@ public class WebUtil {
} }
public static <T> void setAttribute(String name, T obj) { public static <T> void setAttribute(String name, T obj) {
getRequest().setAttribute(sessionUser, obj); getRequest().setAttribute(name, obj);
} }
public static <T> void setSessionUser(T obj) { public static <T> void setSessionUser(T obj) {
......
package com.secoo.mall.mybatis.config; package com.secoo.mall.mybatis.config;
import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.autoconfigure.MybatisPlusProperties;
import com.baomidou.mybatisplus.core.MybatisConfiguration; import com.baomidou.mybatisplus.core.MybatisConfiguration;
import com.baomidou.mybatisplus.core.config.GlobalConfig; import com.baomidou.mybatisplus.core.config.GlobalConfig;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor; import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
...@@ -17,6 +18,7 @@ import org.springframework.context.annotation.Bean; ...@@ -17,6 +18,7 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver; import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import javax.annotation.Resource;
import javax.sql.DataSource; import javax.sql.DataSource;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -29,6 +31,9 @@ public class MybatisConfig { ...@@ -29,6 +31,9 @@ public class MybatisConfig {
@Value("${spring.profiles.active}") @Value("${spring.profiles.active}")
private String profile; private String profile;
@Resource
private MybatisPlusProperties mybatisPlusProperties;
@Bean("mybatisSqlSession") @Bean("mybatisSqlSession")
public SqlSessionFactory sqlSessionFactory(DataSource dataSource, GlobalConfig globalConfig) throws Exception { public SqlSessionFactory sqlSessionFactory(DataSource dataSource, GlobalConfig globalConfig) throws Exception {
MybatisSqlSessionFactoryBean sqlSessionFactory = new MybatisSqlSessionFactoryBean(); MybatisSqlSessionFactoryBean sqlSessionFactory = new MybatisSqlSessionFactoryBean();
......
...@@ -4,8 +4,10 @@ import com.secoo.mall.common.core.errorcode.CommonErrorCode; ...@@ -4,8 +4,10 @@ import com.secoo.mall.common.core.errorcode.CommonErrorCode;
import com.secoo.mall.common.core.exception.BusinessException; import com.secoo.mall.common.core.exception.BusinessException;
import com.secoo.mall.common.core.exception.ParameterException; import com.secoo.mall.common.core.exception.ParameterException;
import com.secoo.mall.common.core.exception.SystemInternalException; import com.secoo.mall.common.core.exception.SystemInternalException;
import com.secoo.mall.common.processor.ExceptionProcessor;
import com.secoo.mall.common.util.log.LoggerUtil; import com.secoo.mall.common.util.log.LoggerUtil;
import com.secoo.mall.common.util.response.ResponseUtil; import com.secoo.mall.common.util.response.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource; import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ExceptionHandler;
...@@ -17,23 +19,34 @@ public class ProtocolExceptionHandler { ...@@ -17,23 +19,34 @@ public class ProtocolExceptionHandler {
@Resource @Resource
private MessageSource messageSource; private MessageSource messageSource;
@ExceptionHandler(BusinessException.class) @Autowired(required = false)
public Object businessExcepstionHandler(BusinessException e) { private ExceptionProcessor exceptionProcessor;
LoggerUtil.warn("businessException info:", e);
return ResponseUtil.getFailResponse(e.getCode(), getMsg(e));
}
@ExceptionHandler(ParameterException.class) @ExceptionHandler({Exception.class})
public Object parameterExceptionHandler(ParameterException e) { public Object exceptionHandler(Exception e) {
String msg = getMsg(e); try {
LoggerUtil.info(msg); if (exceptionProcessor == null) {
return ResponseUtil.getFailResponse(e.getCode(), msg); throw e;
} }
@ExceptionHandler({SystemInternalException.class, Exception.class}) exceptionProcessor.process(e);
public Object exceptionHandler(Exception e) {
} catch (ParameterException ex) {
String msg = getMsg(ex);
LoggerUtil.info(msg);
return ResponseUtil.getFailResponse(ex.getCode(), msg);
} catch (SystemInternalException ex) {
LoggerUtil.error(e); LoggerUtil.error(e);
return ResponseUtil.getFailResponse(CommonErrorCode.SYSTEM_INTERNAL_EXCEPTION.getCode(), CommonErrorCode.SYSTEM_INTERNAL_EXCEPTION.getMsg()); return ResponseUtil.getFailResponse(CommonErrorCode.SYSTEM_INTERNAL_EXCEPTION.getCode(), CommonErrorCode.SYSTEM_INTERNAL_EXCEPTION.getMsg());
} catch (BusinessException ex) {
LoggerUtil.warn("businessException info:", ex);
return ResponseUtil.getFailResponse(ex.getCode(), getMsg(ex));
} catch (Exception ex) {
LoggerUtil.error(ex);
return ResponseUtil.getFailResponse(CommonErrorCode.SYSTEM_INTERNAL_EXCEPTION.getCode(), CommonErrorCode.SYSTEM_INTERNAL_EXCEPTION.getMsg());
}
return null;
} }
......
package com.secoo.mall.common.processor;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public abstract class AbsExceptionProcessor implements ExceptionProcessor{
public void process(Exception e) throws Exception{
log.warn("warn:",e);
convertException(e);
throw e;
}
protected abstract void convertException(Exception e);
}
package com.secoo.mall.common.processor;
import com.secoo.mall.common.core.errorcode.ErrorCode;
import com.secoo.mall.common.core.exception.BusinessException;
import com.secoo.mall.common.util.spring.SpringUtil;
import java.util.Map;
public interface ExceptionProcessor {
/**
* 处理异常
* @param e
* @return
*/
void process(Exception e) throws Exception;
}
...@@ -16,15 +16,19 @@ import org.springframework.web.method.annotation.ExceptionHandlerMethodResolver; ...@@ -16,15 +16,19 @@ import org.springframework.web.method.annotation.ExceptionHandlerMethodResolver;
import java.lang.reflect.Method; import java.lang.reflect.Method;
/**
* 统一拦截异常。
* 不向消费端抛出异常,而是形成response结构
*/
@Activate( @Activate(
group = {CommonConstants.PROVIDER}, order = 1000 group = {CommonConstants.PROVIDER}
) )
public class DefaultExceptionFilter extends ExceptionFilter implements Filter { public class ResponseExceptionFilter extends ExceptionFilter implements Filter {
private Logger log = LoggerFactory.getLogger(DefaultExceptionFilter.class); private Logger log = LoggerFactory.getLogger(ResponseExceptionFilter.class);
public DefaultExceptionFilter() { public ResponseExceptionFilter() {
super.listener = new DefaultExceptionFilter.ExceptionListener(); super.listener = new ResponseExceptionFilter.ExceptionListener();
} }
......
package com.secoo.mall.web.annotation; package com.secoo.mall.web.annotation;
import java.lang.annotation.*;
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface ApiIgnoreJson { public @interface ApiIgnoreJson {
} }
exception=com.secoo.mall.dubbo.filter.DefaultExceptionFilter exception=com.secoo.mall.dubbo.filter.ResponseExceptionFilter
\ No newline at end of file \ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment