上传代码
This commit is contained in:
44
src/main/java/com/nis/restful/ApiVersion.java
Normal file
44
src/main/java/com/nis/restful/ApiVersion.java
Normal file
@@ -0,0 +1,44 @@
|
||||
/**
|
||||
* @Title: ApiVersion.java
|
||||
* @Package com.nis.restful
|
||||
* @Description: TODO(用一句话描述该文件做什么)
|
||||
* @author (darnell)
|
||||
* @date 2016年8月14日 下午3:48:50
|
||||
* @version V1.0
|
||||
*/
|
||||
package com.nis.restful;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import org.springframework.web.bind.annotation.Mapping;
|
||||
|
||||
/**
|
||||
* @ClassName: ApiVersion
|
||||
* @Description: TODO(这里用一句话描述这个类的作用)
|
||||
* @author (darnell)
|
||||
* @date 2016年8月14日 下午3:48:50
|
||||
* @version V1.0
|
||||
*/
|
||||
@Target({ElementType.METHOD, ElementType.TYPE})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@Mapping
|
||||
public @interface ApiVersion {
|
||||
/**
|
||||
*
|
||||
* @Title: value
|
||||
* @Description: TODO(版本号)
|
||||
* @param @return 入参
|
||||
* @return int 返回类型
|
||||
* @author (darnell)
|
||||
* @throws
|
||||
* @date 2016年8月14日 下午3:49:20
|
||||
* @version V1.0
|
||||
*/
|
||||
int value();
|
||||
|
||||
}
|
||||
69
src/main/java/com/nis/restful/ApiVersionCondition.java
Normal file
69
src/main/java/com/nis/restful/ApiVersionCondition.java
Normal file
@@ -0,0 +1,69 @@
|
||||
/**
|
||||
* @Title: ApiVersionCondition.java
|
||||
* @Package com.nis.restful
|
||||
* @Description: TODO(用一句话描述该文件做什么)
|
||||
* @author (darnell)
|
||||
* @date 2016年8月15日 上午10:14:21
|
||||
* @version V1.0
|
||||
*/
|
||||
package com.nis.restful;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.springframework.web.servlet.mvc.condition.RequestCondition;
|
||||
|
||||
/**
|
||||
* @ClassName: ApiVersionCondition
|
||||
* @Description: TODO(定义一个条件筛选器,增加版本号匹配规则)
|
||||
* @author (darnell)
|
||||
* @date 2016年8月15日 上午10:14:21
|
||||
* @version V1.0
|
||||
*/
|
||||
public class ApiVersionCondition implements RequestCondition<ApiVersionCondition> {
|
||||
// 路径中版本的前缀, 这里用 /v[1-9]/的形式
|
||||
private final static Pattern VERSION_PREFIX_PATTERN = Pattern.compile("v(\\d+)");
|
||||
private int apiVersion;
|
||||
|
||||
public ApiVersionCondition(int apiVersion){
|
||||
this.apiVersion = apiVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return apiVersion
|
||||
*/
|
||||
public int getApiVersion() {
|
||||
return apiVersion;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ApiVersionCondition combine(ApiVersionCondition other) {
|
||||
// 采用最后定义优先原则,则方法上的定义覆盖类上面的定义
|
||||
return new ApiVersionCondition(other.getApiVersion());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(ApiVersionCondition other, HttpServletRequest request) {
|
||||
// 优先匹配最新的版本号
|
||||
return other.getApiVersion() - this.apiVersion;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApiVersionCondition getMatchingCondition(HttpServletRequest request) {
|
||||
System.out.println("&&&&&&&&&" + request.getPathInfo());
|
||||
Matcher m = VERSION_PREFIX_PATTERN.matcher(request.getPathInfo());
|
||||
System.out.println("---"+apiVersion);
|
||||
if(m.find()){
|
||||
Integer version = Integer.valueOf(m.group(1));
|
||||
System.out.println("****"+version+"---"+apiVersion);
|
||||
if(version >= this.apiVersion) // 如果请求的版本号大于配置版本号, 则满足
|
||||
return this;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
32
src/main/java/com/nis/restful/AppExceptionHandler.java
Normal file
32
src/main/java/com/nis/restful/AppExceptionHandler.java
Normal file
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
* @Title: AppExceptionHandler.java
|
||||
* @Package com.nis.exceptions
|
||||
* @Description: TODO(用一句话描述该文件做什么)
|
||||
* @author (darnell)
|
||||
* @date 2016年8月24日 上午11:29:42
|
||||
* @version V1.0
|
||||
*/
|
||||
package com.nis.restful;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import com.nis.util.Configurations;
|
||||
|
||||
/**
|
||||
* @ClassName: AppExceptionHandler
|
||||
* @Description: TODO(异常接收)
|
||||
* @author (darnell)
|
||||
* @date 2016年8月24日 上午11:29:42
|
||||
* @version V1.0
|
||||
*/
|
||||
public class AppExceptionHandler extends RestServiceExceptionHandler{
|
||||
@Override
|
||||
public boolean isRestServiceException(HttpServletRequest request){
|
||||
String restServicePath = Configurations.getStringProperty("servicePath", "service");
|
||||
if(request.getServletPath().startsWith(restServicePath)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
145
src/main/java/com/nis/restful/CompileJudgeCode.java
Normal file
145
src/main/java/com/nis/restful/CompileJudgeCode.java
Normal file
@@ -0,0 +1,145 @@
|
||||
package com.nis.restful;
|
||||
|
||||
public enum CompileJudgeCode {
|
||||
/**
|
||||
* 当前编译配置中的groupNum属性值与配置分组groupList大小不等
|
||||
*/
|
||||
GroupNumNEQGroupList(1, "groupNum属性值与groupRelationList大小不等"),
|
||||
/**
|
||||
* 当前编译配置中的groupNum属性值与配置分组groupList大小相等
|
||||
*/
|
||||
GroupNumEQGroupList(2, "groupNum属性值与groupRelationList大小不等"),
|
||||
/**
|
||||
* 当前编译配置中的groupNum属性值与配置分组groupList大小均小于等于8且均大于0
|
||||
*/
|
||||
GroupNumAndListLtEight(3, "groupNum属性值与groupRelationList大小均小于等于8且均大于0"),
|
||||
/**
|
||||
* 当前编译配置中的groupNum属性值大于8
|
||||
*/
|
||||
GroupNumGtEight(4, "groupNum属性值大于8"),
|
||||
/**
|
||||
* 当前编译配置中的配置分组groupList大小大于8
|
||||
*/
|
||||
GroupListGtEight(5, "groupRelationList大小大于8"),
|
||||
|
||||
/**
|
||||
* 当前编译配置中的groupNum属性值等于0
|
||||
*/
|
||||
GroupNumEQZero(6, "groupNum属性值等于0"),
|
||||
/**
|
||||
* 当前编译配置中的配置分组groupList等于0
|
||||
*/
|
||||
GroupListEQZero(7, "groupRelationList大小不能为0"),
|
||||
|
||||
/**
|
||||
* 配置分组中域配置个数大于0
|
||||
*/
|
||||
CompileGroupSizeGtZero(8, "配置分组中的域配置均正常"),
|
||||
|
||||
/**
|
||||
* 配置分组中域配置个数为0
|
||||
*/
|
||||
//CompileGroupSizeEqZero(9, "groupRelationList中有一个或多个groupId在strRegionList或ipRegionList或numRegionList中不存在"),
|
||||
/**
|
||||
* 配置分组集合中存在相同的配置分组id
|
||||
*/
|
||||
CompileGroupIdIsRepeat(10, "groupRelationList中存在相同的groupId"),
|
||||
/**
|
||||
* 有域配置中的配置分组id没有对应的配置分组(在配置分组集合中找不到该配置分组id)
|
||||
*/
|
||||
//CompileGroupIdNotExist(11, "有一个或多个strRegionList或ipRegionList或numRegionList中的groupId在groupRelationList中不存在"),
|
||||
|
||||
/**
|
||||
* 配置分组中的compileId与编译配置中的compileId不一致
|
||||
*/
|
||||
//CoupileGroupListPidIsError(12, "groupRelationList中有一个或多个compileId与编译配置中compileId不一致"),
|
||||
/**
|
||||
* 配置分组 前台不能设置分组为无效
|
||||
*/
|
||||
CompileGroupNotIsInvalid(13, "配置分组不能设置为无效"),
|
||||
/**
|
||||
* 编译为无效 域配置全部不能为无效
|
||||
*/
|
||||
CompileALLIsInvalid(14, "编译配置和域配置不能同时为无效"),
|
||||
/**
|
||||
* 编译为有效 域配置至少有一个为无效
|
||||
*/
|
||||
CompileIsValide(15, "当编译为有效时域配置至少有一个为无效"),
|
||||
/**
|
||||
* 添加配置不能为无效
|
||||
*/
|
||||
CompileIsNotInvalid(16, "添加时不能为无效"),
|
||||
/**
|
||||
* 当编译配置有效时 域配置不能都是空
|
||||
*/
|
||||
CompileNotNull(17, "当编译配置有效时,域配置不能都是空"),
|
||||
|
||||
/**
|
||||
* 缺少配置分组信息
|
||||
*/
|
||||
CompileGroupIsNull(18, "缺少配置分组信息"),
|
||||
|
||||
/**
|
||||
* 缺少ip类域配置信息
|
||||
*/
|
||||
IpRegionIsNull(19, "缺少ip类域配置信息"),
|
||||
|
||||
/**
|
||||
* 缺少字符串类域配置信息
|
||||
*/
|
||||
StrRegionIsNull(20, "缺少字符串类域配置信息"),
|
||||
|
||||
/**
|
||||
* 缺少数值类域配置信息
|
||||
*/
|
||||
NumRegionIsNull(21, "缺少数值类域配置信息"),
|
||||
/**
|
||||
* 编译配置不能为空
|
||||
*/
|
||||
CompileIsNull(22, "编译配置不能为空"),
|
||||
/**
|
||||
* groupNum不能为空
|
||||
*/
|
||||
GroupNumIsNull(23, "groupNum不能为空"),
|
||||
/**
|
||||
* groupRelationList不能为空
|
||||
*/
|
||||
GroupListIsNull(24, "groupRelationList不能为空"),
|
||||
/**
|
||||
* groupRelationList不能为空
|
||||
*/
|
||||
//ServiceType2TableName(25, "域配置中的表名与编译配置的业务类型不一致"),
|
||||
/**
|
||||
* 当前编译配置中的groupNum属性与配置分组groupList大小相等且均大于0小于等于8, 且每个配置分组中域配置个数大于0
|
||||
*/
|
||||
CompileIsOk(26, "编译配置完全正确");
|
||||
|
||||
private final int value; // 错误码
|
||||
private String errorReason; // 错误原因
|
||||
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public String getErrorReason() {
|
||||
return errorReason;
|
||||
}
|
||||
|
||||
public void setErrorReason(String errorReason) {
|
||||
this.errorReason = errorReason;
|
||||
}
|
||||
|
||||
private CompileJudgeCode(int value, String errorReason) {
|
||||
this.value = value;
|
||||
this.errorReason = errorReason;
|
||||
}
|
||||
|
||||
public static CompileJudgeCode valueOf(int errorCode) {
|
||||
for (CompileJudgeCode status : values()) {
|
||||
if (status.value == errorCode) {
|
||||
return status;
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException("No matching constant for [" + errorCode + "]");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* @Title: CustomRequestMappingHandlerMapping.java
|
||||
* @Package com.nis.restful
|
||||
* @Description: TODO(扩展原有hadlerMapping)
|
||||
* @author (darnell)
|
||||
* @date 2016年8月15日 上午10:26:34
|
||||
* @version V1.0
|
||||
*/
|
||||
package com.nis.restful;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.springframework.core.annotation.AnnotationUtils;
|
||||
import org.springframework.web.servlet.mvc.condition.RequestCondition;
|
||||
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
|
||||
|
||||
|
||||
/**
|
||||
* @ClassName: CustomRequestMappingHandlerMapping
|
||||
* @Description: TODO(影射扩展,版本号自定义)
|
||||
* @author (darnell)
|
||||
* @date 2016年8月15日 上午10:26:34
|
||||
* @version V1.0
|
||||
*/
|
||||
public class CustomRequestMappingHandlerMapping extends RequestMappingHandlerMapping {
|
||||
@Override
|
||||
protected RequestCondition<ApiVersionCondition> getCustomTypeCondition(Class<?> handlerType) {
|
||||
ApiVersion apiVersion = AnnotationUtils.findAnnotation(handlerType, ApiVersion.class);
|
||||
return createCondition(apiVersion);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected RequestCondition<ApiVersionCondition> getCustomMethodCondition(Method method) {
|
||||
ApiVersion apiVersion = AnnotationUtils.findAnnotation(method, ApiVersion.class);
|
||||
return createCondition(apiVersion);
|
||||
}
|
||||
|
||||
private RequestCondition<ApiVersionCondition> createCondition(ApiVersion apiVersion) {
|
||||
return apiVersion == null ? null : new ApiVersionCondition(apiVersion.value());
|
||||
}
|
||||
}
|
||||
55
src/main/java/com/nis/restful/DefaultRestErrorConverter.java
Normal file
55
src/main/java/com/nis/restful/DefaultRestErrorConverter.java
Normal file
@@ -0,0 +1,55 @@
|
||||
package com.nis.restful;
|
||||
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import org.springframework.stereotype.Component;
|
||||
import com.fasterxml.jackson.core.JsonGenerationException;
|
||||
import com.fasterxml.jackson.databind.JsonMappingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Component
|
||||
public class DefaultRestErrorConverter implements RestConverter<Map> {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Map convert(RestResult re) {
|
||||
Map errorMap = new LinkedHashMap();
|
||||
errorMap.put(RestConstants.REST_SERVICE_HTTP_STATUS, re.getStatus()
|
||||
.value());
|
||||
errorMap.put(RestConstants.REST_SERVICE_BUSINESS_CODE, re.getBusinessCode()
|
||||
.getValue());
|
||||
errorMap.put(RestConstants.REST_SERVICE_REASON, re.getBusinessCode()
|
||||
.getErrorReason());
|
||||
errorMap.put(RestConstants.REST_SERVICE_MSG, re.getMsg());
|
||||
errorMap.put(RestConstants.REST_SERVICE_URI, re.getFromUri());
|
||||
|
||||
if(re.getActiveSys() != null){
|
||||
errorMap.put(RestConstants.REST_SERVICE_ACTIVE_SYS, re.getActiveSys());
|
||||
}
|
||||
if(re.getLogSource() != null){
|
||||
errorMap.put(RestConstants.REST_SERVICE_LOG_SOURCE, re.getLogSource());
|
||||
}
|
||||
|
||||
return errorMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String convertToJson(RestResult re) {
|
||||
Map errorMap = this.convert(re);
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
try {
|
||||
return mapper.writeValueAsString(errorMap);
|
||||
} catch (JsonGenerationException e) {
|
||||
e.printStackTrace();
|
||||
} catch (JsonMappingException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
}
|
||||
163
src/main/java/com/nis/restful/DefaultRestErrorResolver.java
Normal file
163
src/main/java/com/nis/restful/DefaultRestErrorResolver.java
Normal file
@@ -0,0 +1,163 @@
|
||||
package com.nis.restful;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import org.springframework.beans.TypeMismatchException;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.converter.HttpMessageNotReadableException;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.HttpMediaTypeNotAcceptableException;
|
||||
import org.springframework.web.HttpMediaTypeNotSupportedException;
|
||||
import org.springframework.web.HttpRequestMethodNotSupportedException;
|
||||
import org.springframework.web.bind.MissingServletRequestParameterException;
|
||||
import org.springframework.web.servlet.mvc.multiaction.NoSuchRequestHandlingMethodException;
|
||||
@Component
|
||||
public class DefaultRestErrorResolver implements RestErrorResolver,InitializingBean{
|
||||
|
||||
/**
|
||||
* 预先定义的所有异常类型
|
||||
*/
|
||||
private Map<String, String> exceptionMappings = Collections.emptyMap();
|
||||
|
||||
/**
|
||||
* 配置文件中自定义扩展错误
|
||||
*/
|
||||
private Map<String, String> exceptionMappingDefinitions = Collections.emptyMap();
|
||||
|
||||
|
||||
@Override
|
||||
public RestResult resolveError(HttpServletRequest request, Object handler,
|
||||
Exception ex) {
|
||||
RestResult error = this.buildError(ex, request);
|
||||
return error;
|
||||
}
|
||||
|
||||
|
||||
private RestResult buildError(Exception ex, HttpServletRequest request) {
|
||||
RestResult error = new RestResult();
|
||||
error.setStatus(this.getHttpStatusByEx(ex));// 设置http状态
|
||||
//获取日志源[只有日志需要返回日志源和ActiveSys]
|
||||
String logSource = ((RestServiceException) ex).getLogSource();
|
||||
String activeSys = ((RestServiceException) ex).getActiveSys();
|
||||
if(logSource != null ){
|
||||
error.setLogSource(logSource);
|
||||
}
|
||||
if(activeSys != null ){
|
||||
error.setActiveSys(activeSys);
|
||||
}
|
||||
|
||||
//RestServiceException 包含有错误code
|
||||
if(ex instanceof RestServiceException){
|
||||
int errorCode = ((RestServiceException) ex).getErrorCode();
|
||||
error.setBusinessCode(RestBusinessCode.valueOf(errorCode));
|
||||
} else {
|
||||
error.setBusinessCode(RestBusinessCode.valueOf(998));
|
||||
}
|
||||
|
||||
error.setMsg(ex.getMessage());
|
||||
if(null != request){
|
||||
error.setFromUri(request.getRequestURI());
|
||||
}else {
|
||||
error.setFromUri("unknow url");
|
||||
}
|
||||
return error;
|
||||
}
|
||||
|
||||
private HttpStatus getHttpStatusByEx(Exception ex){
|
||||
if(this.exceptionMappingDefinitions.containsKey(ex.getClass().getName())){
|
||||
return HttpStatus.valueOf(Integer.parseInt(this.exceptionMappingDefinitions.get(ex.getClass()
|
||||
.getName())));
|
||||
}
|
||||
else return HttpStatus.INTERNAL_SERVER_ERROR;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
//初始化所有预先定义的错误
|
||||
this.exceptionMappings = createDefaultExceptionMappingDefinitions();
|
||||
//如果存在自定义的错误,添加到预定义错误中
|
||||
if (this.exceptionMappingDefinitions != null && !this.exceptionMappingDefinitions.isEmpty()) {
|
||||
this.exceptionMappings.putAll(this.exceptionMappingDefinitions);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将spring中的http状态和异常互相对应 参考 spring的defaultExceptionHandler实现类似
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private final Map<String, String> createDefaultExceptionMappingDefinitions() {
|
||||
|
||||
Map<String, String> m = new LinkedHashMap<String, String>();
|
||||
|
||||
// 400
|
||||
applyDef(m, HttpMessageNotReadableException.class,
|
||||
HttpStatus.BAD_REQUEST);
|
||||
applyDef(m, MissingServletRequestParameterException.class,
|
||||
HttpStatus.BAD_REQUEST);
|
||||
applyDef(m, TypeMismatchException.class, HttpStatus.BAD_REQUEST);
|
||||
applyDef(m, "javax.validation.ValidationException",
|
||||
HttpStatus.BAD_REQUEST);
|
||||
|
||||
// 404
|
||||
applyDef(m, NoSuchRequestHandlingMethodException.class,
|
||||
HttpStatus.NOT_FOUND);
|
||||
applyDef(m, "org.hibernate.ObjectNotFoundException",
|
||||
HttpStatus.NOT_FOUND);
|
||||
|
||||
// 405
|
||||
applyDef(m, HttpRequestMethodNotSupportedException.class,
|
||||
HttpStatus.METHOD_NOT_ALLOWED);
|
||||
|
||||
// 406
|
||||
applyDef(m, HttpMediaTypeNotAcceptableException.class,
|
||||
HttpStatus.NOT_ACCEPTABLE);
|
||||
|
||||
// 409
|
||||
applyDef(m, "org.springframework.dao.DataIntegrityViolationException",
|
||||
HttpStatus.CONFLICT);
|
||||
|
||||
// 415
|
||||
applyDef(m, HttpMediaTypeNotSupportedException.class,
|
||||
HttpStatus.UNSUPPORTED_MEDIA_TYPE);
|
||||
return m;
|
||||
}
|
||||
|
||||
private void applyDef(Map<String, String> m, Class clazz, HttpStatus status) {
|
||||
applyDef(m, clazz.getName(), status);
|
||||
}
|
||||
|
||||
private void applyDef(Map<String, String> m, String key, HttpStatus status) {
|
||||
m.put(key, status.value() + "");
|
||||
}
|
||||
|
||||
|
||||
public Map<String, String> getExceptionMappings() {
|
||||
return exceptionMappings;
|
||||
}
|
||||
|
||||
|
||||
public void setExceptionMappings(Map<String, String> exceptionMappings) {
|
||||
this.exceptionMappings = exceptionMappings;
|
||||
}
|
||||
|
||||
|
||||
public Map<String, String> getExceptionMappingDefinitions() {
|
||||
return exceptionMappingDefinitions;
|
||||
}
|
||||
|
||||
|
||||
public void setExceptionMappingDefinitions(
|
||||
Map<String, String> exceptionMappingDefinitions) {
|
||||
this.exceptionMappingDefinitions = exceptionMappingDefinitions;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
/**
|
||||
* @Title: DefaultRestSuccessConverter.java
|
||||
* @Package com.nis.restful
|
||||
* @Description: TODO(用一句话描述该文件做什么)
|
||||
* @author (darnell)
|
||||
* @date 2016年8月24日 下午4:24:22
|
||||
* @version V1.0
|
||||
*/
|
||||
package com.nis.restful;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonGenerationException;
|
||||
import com.fasterxml.jackson.databind.JsonMappingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
/**
|
||||
* @ClassName: DefaultRestSuccessConverter
|
||||
* @Description: TODO(这里用一句话描述这个类的作用)
|
||||
* @author (darnell)
|
||||
* @date 2016年8月24日 下午4:24:22
|
||||
* @version V1.0
|
||||
*/
|
||||
public class DefaultRestSuccessConverter implements RestConverter<Map> {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Map convert(RestResult re) {
|
||||
Map successMap = new LinkedHashMap();
|
||||
successMap.put(RestConstants.REST_SERVICE_HTTP_STATUS, re.getStatus()
|
||||
.value());
|
||||
successMap.put(RestConstants.REST_SERVICE_BUSINESS_CODE, re.getBusinessCode()
|
||||
.getValue());
|
||||
successMap.put(RestConstants.REST_SERVICE_REASON, re.getBusinessCode()
|
||||
.getErrorReason());
|
||||
successMap.put(RestConstants.REST_SERVICE_MSG, re.getMsg());
|
||||
successMap.put(RestConstants.REST_SERVICE_URI, re.getFromUri());
|
||||
|
||||
return successMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String convertToJson(RestResult re) {
|
||||
Map successMap = this.convert(re);
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
try {
|
||||
return mapper.writeValueAsString(successMap);
|
||||
} catch (JsonGenerationException e) {
|
||||
e.printStackTrace();
|
||||
} catch (JsonMappingException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
99
src/main/java/com/nis/restful/RestBusinessCode.java
Normal file
99
src/main/java/com/nis/restful/RestBusinessCode.java
Normal file
@@ -0,0 +1,99 @@
|
||||
package com.nis.restful;
|
||||
|
||||
/*
|
||||
* 服务业务编码
|
||||
*/
|
||||
public enum RestBusinessCode {
|
||||
|
||||
/**
|
||||
* 未知错误
|
||||
*/
|
||||
unknow_error (998, "未知错误!"),
|
||||
/**
|
||||
* 需要权限
|
||||
*/
|
||||
need_permission (1000 ,"该操作需要权限"),
|
||||
/**
|
||||
* 资源不存在
|
||||
*/
|
||||
uri_not_found (1001,"uri地址不存在,检查uri拼写"),
|
||||
|
||||
|
||||
/**
|
||||
* 参数不全
|
||||
*/
|
||||
missing_args (1002,"缺少必要的参数信息"),
|
||||
|
||||
/**
|
||||
* 操作行为错误,1-插入2-更新 3-删除4-查询 ,插入时选择了删除这种错误返回该异常代码
|
||||
*/
|
||||
|
||||
op_action_error (1003,"不正确的操作行为"),
|
||||
|
||||
config_integrity_error (1004,"配置完整性错误或数据格式错误"),
|
||||
|
||||
param_formate_error (1005,"服务器请求参数格式错误"),
|
||||
|
||||
insert_data_repeat (1006,"新增数据重复"),
|
||||
|
||||
log_range_undefined (1007,"服务器请求日志范围不明确"),
|
||||
|
||||
not_unique (1008,"数据违反唯一性"),
|
||||
|
||||
wrong_range (1009,"数据不在有效范围"),
|
||||
|
||||
query_success(2000, "数据获取操作成功"),
|
||||
|
||||
add_success(2001, "数据添加操作成功"),
|
||||
|
||||
update_success(2002, "数据更新操作成功"),
|
||||
|
||||
delete_success(2003, "数据删除操作成功");
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private final int value; //错误码
|
||||
private final String errorReason; //错误原因
|
||||
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public String getErrorReason() {
|
||||
return errorReason;
|
||||
}
|
||||
|
||||
|
||||
private RestBusinessCode(int value, String errorReason) {
|
||||
this.value = value;
|
||||
this.errorReason = errorReason;
|
||||
}
|
||||
|
||||
|
||||
public static RestBusinessCode valueOf(int errorCode) {
|
||||
for (RestBusinessCode status : values()) {
|
||||
if (status.value == errorCode) {
|
||||
return status;
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException("No matching constant for [" + errorCode + "]");
|
||||
}
|
||||
|
||||
}
|
||||
32
src/main/java/com/nis/restful/RestConstants.java
Normal file
32
src/main/java/com/nis/restful/RestConstants.java
Normal file
@@ -0,0 +1,32 @@
|
||||
package com.nis.restful;
|
||||
|
||||
|
||||
public class RestConstants {
|
||||
/**
|
||||
* json报文字段
|
||||
*/
|
||||
public static final String REST_SERVICE_HTTP_STATUS = "status";
|
||||
|
||||
public static final String REST_SERVICE_BUSINESS_CODE = "businessCode";
|
||||
|
||||
public static final String REST_SERVICE_REASON = "reason";
|
||||
|
||||
public static final String REST_SERVICE_MSG = "msg";
|
||||
|
||||
public static final String REST_SERVICE_DATA = "data";
|
||||
|
||||
public static final String REST_SERVICE_URI = "fromuri";
|
||||
|
||||
public static final String REST_SERVICE_ACTIVE_SYS = "activeSys";
|
||||
|
||||
public static final String REST_SERVICE_LOG_SOURCE = "logSource";
|
||||
|
||||
//暂时4个
|
||||
|
||||
/**
|
||||
* code错误码
|
||||
*/
|
||||
|
||||
|
||||
|
||||
}
|
||||
20
src/main/java/com/nis/restful/RestConverter.java
Normal file
20
src/main/java/com/nis/restful/RestConverter.java
Normal file
@@ -0,0 +1,20 @@
|
||||
package com.nis.restful;
|
||||
|
||||
|
||||
public interface RestConverter<T> {
|
||||
|
||||
/**
|
||||
* 将错误对象转化成map,用于页面的输出
|
||||
* @return
|
||||
*/
|
||||
|
||||
T convert(RestResult re);
|
||||
|
||||
/**
|
||||
* 转化为json字串
|
||||
* @param re
|
||||
* @return
|
||||
*/
|
||||
String convertToJson(RestResult re);
|
||||
|
||||
}
|
||||
29
src/main/java/com/nis/restful/RestErrorResolver.java
Normal file
29
src/main/java/com/nis/restful/RestErrorResolver.java
Normal file
@@ -0,0 +1,29 @@
|
||||
/**
|
||||
* @Title: RestErrorResolver.java
|
||||
* @Package com.nis.restful
|
||||
* @Description: TODO(用一句话描述该文件做什么)
|
||||
* @author (darnell)
|
||||
* @date 2016年8月24日 上午11:35:18
|
||||
* @version V1.0
|
||||
*/
|
||||
package com.nis.restful;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* @ClassName: RestErrorResolver
|
||||
* @Description: TODO(异常和错误对象的转换接口)
|
||||
* @author (darnell)
|
||||
* @date 2016年8月24日 上午11:35:18
|
||||
* @version V1.0
|
||||
*/
|
||||
public interface RestErrorResolver {
|
||||
/**
|
||||
*
|
||||
* @param request 请求
|
||||
* @param handler 处理方法
|
||||
* @param ex 异常
|
||||
* @return
|
||||
*/
|
||||
RestResult resolveError(HttpServletRequest request, Object handler, Exception ex);
|
||||
}
|
||||
167
src/main/java/com/nis/restful/RestResult.java
Normal file
167
src/main/java/com/nis/restful/RestResult.java
Normal file
@@ -0,0 +1,167 @@
|
||||
/**
|
||||
* @Title: RestError.java
|
||||
* @Package com.nis.restful
|
||||
* @Description: TODO(用一句话描述该文件做什么)
|
||||
* @author (darnell)
|
||||
* @date 2016年8月24日 上午11:36:30
|
||||
* @version V1.0
|
||||
*/
|
||||
package com.nis.restful;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
||||
/**
|
||||
* @ClassName: RestError
|
||||
* @Description: TODO(用于构建web服务的错误对象)
|
||||
* @author (darnell)
|
||||
* @date 2016年8月24日 上午11:36:30
|
||||
* @version V1.0
|
||||
*/
|
||||
public class RestResult {
|
||||
|
||||
/**
|
||||
* http状态码
|
||||
*/
|
||||
private HttpStatus status;
|
||||
|
||||
/**
|
||||
* 业务编码
|
||||
*/
|
||||
private RestBusinessCode businessCode;
|
||||
|
||||
/**
|
||||
* 结果信息
|
||||
*/
|
||||
private String msg;
|
||||
|
||||
/**
|
||||
* 请求来源
|
||||
*/
|
||||
private String fromUri;
|
||||
|
||||
private Object data;
|
||||
/**
|
||||
* A版:4 B版:2 C版:1
|
||||
*/
|
||||
private String activeSys;
|
||||
|
||||
/**
|
||||
* 日志数据来源本地:0 数据中心:1
|
||||
*/
|
||||
private String logSource;
|
||||
|
||||
public RestResult(){
|
||||
|
||||
}
|
||||
|
||||
public RestResult(HttpStatus status, RestBusinessCode businessCode, String msg,String fromUri,String activeSys,String fromSign) {
|
||||
super();
|
||||
this.status = status;
|
||||
this.businessCode = businessCode;
|
||||
this.msg = msg;
|
||||
this.fromUri = fromUri;
|
||||
this.activeSys=activeSys;
|
||||
this.logSource=logSource;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return status
|
||||
*/
|
||||
public HttpStatus getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param status 要设置的 status
|
||||
*/
|
||||
public void setStatus(HttpStatus status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return businessCode
|
||||
*/
|
||||
public RestBusinessCode getBusinessCode() {
|
||||
return businessCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param businessCode 要设置的 businessCode
|
||||
*/
|
||||
public void setBusinessCode(RestBusinessCode businessCode) {
|
||||
this.businessCode = businessCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return msg
|
||||
*/
|
||||
public String getMsg() {
|
||||
return msg;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param msg 要设置的 msg
|
||||
*/
|
||||
public void setMsg(String msg) {
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return fromUri
|
||||
*/
|
||||
public String getFromUri() {
|
||||
return fromUri;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param fromUri 要设置的 fromUri
|
||||
*/
|
||||
public void setFromUri(String fromUri) {
|
||||
this.fromUri = fromUri;
|
||||
}
|
||||
|
||||
public String getActiveSys() {
|
||||
return activeSys;
|
||||
}
|
||||
|
||||
public void setActiveSys(String activeSys) {
|
||||
this.activeSys = activeSys;
|
||||
}
|
||||
|
||||
public String getLogSource() {
|
||||
return logSource;
|
||||
}
|
||||
public void setLogSource(String logSource) {
|
||||
this.logSource = logSource;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return data
|
||||
*/
|
||||
public Object getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param data 要设置的 data
|
||||
*/
|
||||
public void setData(Object data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return new StringBuilder().append("HttpStatus:").append(getStatus().value())
|
||||
.append(" errorcode:")
|
||||
.append(this.getBusinessCode().getValue())
|
||||
.append(" errorReason:")
|
||||
.append(this.getBusinessCode().getErrorReason())
|
||||
.append(" errorMsg:")
|
||||
.append(this.getMsg())
|
||||
.append(" errorURL").append(this.getFromUri())
|
||||
.toString();
|
||||
}
|
||||
|
||||
}
|
||||
76
src/main/java/com/nis/restful/RestServiceException.java
Normal file
76
src/main/java/com/nis/restful/RestServiceException.java
Normal file
@@ -0,0 +1,76 @@
|
||||
package com.nis.restful;
|
||||
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.nis.web.service.SaveRequestLogThread;
|
||||
|
||||
public class RestServiceException extends RuntimeException{
|
||||
|
||||
private int errorCode;
|
||||
|
||||
private String logSource;
|
||||
|
||||
private String activeSys;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -4854901217206974677L;
|
||||
|
||||
|
||||
public RestServiceException(){
|
||||
}
|
||||
|
||||
|
||||
// public RestServiceException(String message) {
|
||||
// super(message);
|
||||
// this.errorCode = 998; //未知错误
|
||||
// }
|
||||
public RestServiceException(SaveRequestLogThread thread,long time,String message) {
|
||||
super(message);
|
||||
this.errorCode = 998; //未知错误
|
||||
thread.setConsumerTime(time);
|
||||
thread.setBusinessCode(this.getErrorCode());
|
||||
if(StringUtils.isEmpty(thread.getExceptionInfo()))
|
||||
thread.setExceptionInfo(message);
|
||||
new Thread(thread).start();
|
||||
}
|
||||
|
||||
public RestServiceException(String message,int errorCode) {
|
||||
super(message);
|
||||
this.errorCode = errorCode;
|
||||
}
|
||||
public RestServiceException(SaveRequestLogThread thread,long time,String message,int errorCode) {
|
||||
super(message);
|
||||
this.errorCode = errorCode;
|
||||
thread.setConsumerTime(time);
|
||||
thread.setBusinessCode(this.getErrorCode());
|
||||
if(StringUtils.isEmpty(thread.getExceptionInfo()))
|
||||
thread.setExceptionInfo(message);
|
||||
new Thread(thread).start();
|
||||
}
|
||||
|
||||
public int getErrorCode() {
|
||||
return errorCode;
|
||||
}
|
||||
|
||||
|
||||
public void setErrorCode(int errorCode) {
|
||||
this.errorCode = errorCode;
|
||||
}
|
||||
|
||||
public String getLogSource() {
|
||||
return logSource;
|
||||
}
|
||||
public void setLogSource(String logSource) {
|
||||
this.logSource = logSource;
|
||||
}
|
||||
public String getActiveSys() {
|
||||
return activeSys;
|
||||
}
|
||||
public void setActiveSys(String activeSys) {
|
||||
this.activeSys = activeSys;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
/**
|
||||
* @Title: RestServiceExceptionHandler.java
|
||||
* @Package com.nis.restful
|
||||
* @Description: TODO(用一句话描述该文件做什么)
|
||||
* @author (darnell)
|
||||
* @date 2016年8月24日 上午11:31:47
|
||||
* @version V1.0
|
||||
*/
|
||||
package com.nis.restful;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
import org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonEncoding;
|
||||
import com.fasterxml.jackson.core.JsonGenerationException;
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.databind.JsonMappingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
/**
|
||||
* @ClassName: RestServiceExceptionHandler
|
||||
* @Description: TODO(rest异常处理,需要判断是否为rest异常,如果不是,则交给正常页面异常处理,否则抛出json格式错误.判断是否rest异常需要具体项目具体实现,默认统一为true)
|
||||
* @author (darnell)
|
||||
* @date 2016年8月24日 上午11:31:47
|
||||
* @version V1.0
|
||||
*/
|
||||
public class RestServiceExceptionHandler extends DefaultHandlerExceptionResolver{
|
||||
|
||||
protected static final Logger LOGGER = LoggerFactory.getLogger(RestServiceExceptionHandler.class);
|
||||
|
||||
/**
|
||||
* 通过xml文件配置,可能存在自定义的异常类型
|
||||
*/
|
||||
private RestErrorResolver errorResolver;
|
||||
|
||||
@Autowired
|
||||
private RestConverter<?> errorConverter; //错误信息转换器
|
||||
|
||||
/**
|
||||
* 确认是否rest服务方法,需要子类重写
|
||||
* 如果不是则不做处理,直接交给父类处理
|
||||
* @param request
|
||||
* @return 是否为rest服务
|
||||
*/
|
||||
public boolean isRestServiceException(HttpServletRequest request){
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ModelAndView doResolveException(HttpServletRequest request,
|
||||
HttpServletResponse response, Object handler, Exception ex) {
|
||||
if (isRestServiceException(request)) {
|
||||
RestResult error = errorResolver.resolveError(request, handler, ex);
|
||||
response.setStatus(error.getStatus().value());
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
response.setContentType("application/json");
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
try {
|
||||
JsonGenerator jsonGenerator = mapper.getFactory()
|
||||
.createGenerator(response.getOutputStream(),
|
||||
JsonEncoding.UTF8);
|
||||
mapper.writeValue(jsonGenerator, errorConverter.convert(error));
|
||||
} catch (JsonGenerationException e) {
|
||||
e.printStackTrace();
|
||||
} catch (JsonMappingException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return new ModelAndView();
|
||||
} else {
|
||||
return super.doResolveException(request, response, handler, ex);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public RestErrorResolver getErrorResolver() {
|
||||
return errorResolver;
|
||||
}
|
||||
|
||||
public void setErrorResolver(RestErrorResolver errorResolver) {
|
||||
this.errorResolver = errorResolver;
|
||||
}
|
||||
|
||||
}
|
||||
64
src/main/java/com/nis/restful/SwaggerConfig.java
Normal file
64
src/main/java/com/nis/restful/SwaggerConfig.java
Normal file
@@ -0,0 +1,64 @@
|
||||
/**
|
||||
* @Title: SwaggerConfig.java
|
||||
* @Package com.nis.restful
|
||||
* @Description: TODO(用一句话描述该文件做什么)
|
||||
* @author (darnell)
|
||||
* @date 2016年8月15日 下午2:16:51
|
||||
* @version V1.0
|
||||
*/
|
||||
package com.nis.restful;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import com.mangofactory.swagger.configuration.SpringSwaggerConfig;
|
||||
import com.mangofactory.swagger.models.dto.ApiInfo;
|
||||
import com.mangofactory.swagger.plugin.EnableSwagger;
|
||||
import com.mangofactory.swagger.plugin.SwaggerSpringMvcPlugin;
|
||||
|
||||
/**
|
||||
* @ClassName: SwaggerConfig
|
||||
* @Description: TODO(这里用一句话描述这个类的作用)
|
||||
* @author (darnell)
|
||||
* @date 2016年8月15日 下午2:16:51
|
||||
* @version V1.0
|
||||
*/
|
||||
@Configuration
|
||||
@EnableSwagger
|
||||
public class SwaggerConfig {
|
||||
private SpringSwaggerConfig springSwaggerConfig;
|
||||
@Autowired
|
||||
public void setSpringSwaggerConfig(SpringSwaggerConfig springSwaggerConfig)
|
||||
{
|
||||
this.springSwaggerConfig = springSwaggerConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* Every SwaggerSpringMvcPlugin bean is picked up by the swagger-mvc
|
||||
* framework - allowing for multiple swagger groups i.e. same code base
|
||||
* multiple swagger resource listings.
|
||||
*/
|
||||
@Bean
|
||||
public SwaggerSpringMvcPlugin customImplementation()
|
||||
{
|
||||
return new SwaggerSpringMvcPlugin(this.springSwaggerConfig)
|
||||
.apiInfo(apiInfo())
|
||||
.includePatterns(".service*.*")//api过滤
|
||||
.swaggerGroup("XmPlatform")
|
||||
.apiVersion("1.0");
|
||||
// .includePatterns(".*?");
|
||||
}
|
||||
|
||||
private ApiInfo apiInfo()
|
||||
{
|
||||
ApiInfo apiInfo = new ApiInfo(
|
||||
"文本综合业务 API",
|
||||
"API Document 管理",
|
||||
"V1.0",
|
||||
"doufenghu@iie.ac.cn",
|
||||
"My Apps API Licence Type",
|
||||
"http://127.0.0.1:8080/gk/swagger/");
|
||||
return apiInfo;
|
||||
}
|
||||
}
|
||||
33
src/main/java/com/nis/restful/WebConfig.java
Normal file
33
src/main/java/com/nis/restful/WebConfig.java
Normal file
@@ -0,0 +1,33 @@
|
||||
/**
|
||||
* @Title: WebConfig.java
|
||||
* @Package com.nis.restful
|
||||
* @Description: TODO(去掉前面说的<mvc:annotation-driven/>这个配置,我们通过JavaConfig的方式注入)
|
||||
* @author (darnell)
|
||||
* @date 2016年8月15日 上午10:34:18
|
||||
* @version V1.0
|
||||
*/
|
||||
package com.nis.restful;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
|
||||
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
|
||||
|
||||
/**
|
||||
* @ClassName: WebConfig
|
||||
* @Description: TODO(这里用一句话描述这个类的作用)
|
||||
* @author (darnell)
|
||||
* @date 2016年8月15日 上午10:34:18
|
||||
* @version V1.0
|
||||
*/
|
||||
@Configuration
|
||||
public class WebConfig extends WebMvcConfigurationSupport{
|
||||
@Override
|
||||
@Bean
|
||||
public RequestMappingHandlerMapping requestMappingHandlerMapping() {
|
||||
RequestMappingHandlerMapping handlerMapping = new CustomRequestMappingHandlerMapping();
|
||||
handlerMapping.setOrder(0);
|
||||
handlerMapping.setInterceptors(getInterceptors());
|
||||
return handlerMapping;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user