fix: 修改pom
This commit is contained in:
@@ -62,5 +62,10 @@
|
|||||||
<groupId>org.apache.rocketmq</groupId>
|
<groupId>org.apache.rocketmq</groupId>
|
||||||
<artifactId>rocketmq-client</artifactId>
|
<artifactId>rocketmq-client</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.tomcat.embed</groupId>
|
||||||
|
<artifactId>tomcat-embed-core</artifactId>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@@ -0,0 +1,112 @@
|
|||||||
|
|
||||||
|
package com.maquan_ceshi.maquan_ceshi.common.response;
|
||||||
|
|
||||||
|
import com.vs.common.util.rpc.pub.FailData;
|
||||||
|
import com.vs.ox.common.exception.ErrorCode;
|
||||||
|
import com.vs.ox.common.exception.IgnoredException;
|
||||||
|
import com.vs.ox.common.utils.ObjectMapperFactory;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.PrintWriter;
|
||||||
|
import java.io.StringWriter;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import javax.validation.ConstraintViolation;
|
||||||
|
import javax.validation.ConstraintViolationException;
|
||||||
|
import javax.validation.Path;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.InitializingBean;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.http.converter.HttpMessageConverter;
|
||||||
|
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
||||||
|
import org.springframework.http.server.ServletServerHttpResponse;
|
||||||
|
import org.springframework.web.servlet.ModelAndView;
|
||||||
|
import org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver;
|
||||||
|
|
||||||
|
public class ResponseJsonExceptionResolver extends AbstractHandlerExceptionResolver implements InitializingBean {
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(ResponseJsonExceptionResolver.class);
|
||||||
|
private HttpMessageConverter messageConverter;
|
||||||
|
|
||||||
|
public ResponseJsonExceptionResolver() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public void afterPropertiesSet() throws Exception {
|
||||||
|
if (this.messageConverter == null) {
|
||||||
|
this.messageConverter = new MappingJackson2HttpMessageConverter(ObjectMapperFactory.getDefaultObjectMapper());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getErrorInfoFromException(Exception e) {
|
||||||
|
try {
|
||||||
|
StringWriter sw = new StringWriter();
|
||||||
|
PrintWriter pw = new PrintWriter(sw);
|
||||||
|
e.printStackTrace(pw);
|
||||||
|
return "\r\n" + sw.toString() + "\r\n";
|
||||||
|
} catch (Exception var3) {
|
||||||
|
return "bad getErrorInfoFromException";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ModelAndView doResolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
|
||||||
|
FailData failData = new FailData();
|
||||||
|
failData.setMessage(ex.getMessage());
|
||||||
|
if (ex instanceof IgnoredException) {
|
||||||
|
IgnoredException realEx = (IgnoredException)ex;
|
||||||
|
failData.setCode(realEx.getErrorCode());
|
||||||
|
failData.setData(realEx.getData());
|
||||||
|
log.error("execute {} failed with exception", request.getRequestURL(), ex);
|
||||||
|
} else if (ex instanceof ConstraintViolationException) {
|
||||||
|
failData.setCode(400);
|
||||||
|
failData.setMessage(getMessage((ConstraintViolationException)ex));
|
||||||
|
} else if (ex instanceof ErrorCode) {
|
||||||
|
failData.setCode(((ErrorCode)ex).getErrorCode());
|
||||||
|
} else {
|
||||||
|
log.error("execute {} failed with exception", request.getRequestURL(), ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
response.setCharacterEncoding("utf-8");
|
||||||
|
this.messageConverter.write(failData, MediaType.APPLICATION_JSON, new ServletServerHttpResponse(response));
|
||||||
|
} catch (IOException var7) {
|
||||||
|
this.logger.error(var7.getMessage(), var7);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new ModelAndView();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getOrder() {
|
||||||
|
return Integer.MAX_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getMessage(ConstraintViolationException e) {
|
||||||
|
List<String> msgList = new ArrayList();
|
||||||
|
Iterator var2 = e.getConstraintViolations().iterator();
|
||||||
|
|
||||||
|
while(var2.hasNext()) {
|
||||||
|
ConstraintViolation<?> constraintViolation = (ConstraintViolation)var2.next();
|
||||||
|
int i = 0;
|
||||||
|
StringBuilder param = new StringBuilder();
|
||||||
|
|
||||||
|
for(Iterator<Path.Node> iterator = constraintViolation.getPropertyPath().iterator(); iterator.hasNext(); ++i) {
|
||||||
|
Path.Node node = (Path.Node)iterator.next();
|
||||||
|
if (i != 0) {
|
||||||
|
if (!param.toString().isBlank()) {
|
||||||
|
param.append(".");
|
||||||
|
}
|
||||||
|
|
||||||
|
param.append(node.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String var10001 = String.valueOf(param);
|
||||||
|
msgList.add("参数 [ " + var10001 + " ] " + constraintViolation.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
return StringUtils.join(msgList.toArray(), ";");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
package com.maquan_ceshi.maquan_ceshi.common.response;
|
||||||
|
|
||||||
|
import com.vs.common.util.rpc.pub.PublicInterface;
|
||||||
|
import com.vs.common.util.rpc.pub.SuccessData;
|
||||||
|
import com.vs.ox.common.utils.ObjectMapperFactory;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.InitializingBean;
|
||||||
|
import org.springframework.core.MethodParameter;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.http.converter.HttpMessageConverter;
|
||||||
|
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
||||||
|
import org.springframework.http.server.ServletServerHttpResponse;
|
||||||
|
import org.springframework.web.context.request.NativeWebRequest;
|
||||||
|
import org.springframework.web.method.support.HandlerMethodReturnValueHandler;
|
||||||
|
import org.springframework.web.method.support.ModelAndViewContainer;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.Collections;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理 Controller 里的返回值,从 Object 包装为 ResultDTO 类型
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
public class ResponseJsonMethodReturnValueHandler implements HandlerMethodReturnValueHandler, InitializingBean {
|
||||||
|
private HttpMessageConverter messageConverter;
|
||||||
|
|
||||||
|
public ResponseJsonMethodReturnValueHandler() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public void afterPropertiesSet() {
|
||||||
|
if (this.messageConverter == null) {
|
||||||
|
this.messageConverter = new MappingJackson2HttpMessageConverter(ObjectMapperFactory.getDefaultObjectMapper());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean supportsReturnType(MethodParameter returnType) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void handleReturnValue(Object returnValue, MethodParameter returnType, ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception {
|
||||||
|
Method method = returnType.getMethod();
|
||||||
|
//目前只处理自动生成接口
|
||||||
|
PublicInterface annotation = method.getAnnotation(PublicInterface.class);
|
||||||
|
if (annotation != null) {
|
||||||
|
mavContainer.setRequestHandled(true);
|
||||||
|
Object result = returnValue == null ? new SuccessData(Collections.emptyMap()) : new SuccessData(returnValue);
|
||||||
|
ServletServerHttpResponse response = new ServletServerHttpResponse(webRequest.getNativeResponse(HttpServletResponse.class));
|
||||||
|
this.messageConverter.write(result, new MediaType(MediaType.APPLICATION_JSON, Collections.singletonMap("charset", "utf-8")), response);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,83 @@
|
|||||||
|
package com.maquan_ceshi.maquan_ceshi.common.response;
|
||||||
|
|
||||||
|
import org.springframework.beans.BeansException;
|
||||||
|
import org.springframework.context.ApplicationContext;
|
||||||
|
import org.springframework.context.ApplicationContextAware;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.web.method.annotation.MapMethodProcessor;
|
||||||
|
import org.springframework.web.method.support.HandlerMethodReturnValueHandler;
|
||||||
|
import org.springframework.web.servlet.HandlerExceptionResolver;
|
||||||
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||||
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
||||||
|
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter;
|
||||||
|
import org.springframework.web.servlet.mvc.method.annotation.ViewNameMethodReturnValueHandler;
|
||||||
|
|
||||||
|
import javax.servlet.ServletContextEvent;
|
||||||
|
import javax.servlet.ServletContextListener;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class ResponseJsonWebMvcConfiguration extends WebMvcConfigurerAdapter implements ApplicationContextAware, WebMvcConfigurer {
|
||||||
|
private RequestMappingHandlerAdapter requestMappingHandlerAdapter;
|
||||||
|
private ApplicationContext applicationContext;
|
||||||
|
|
||||||
|
void init() {
|
||||||
|
List<HandlerMethodReturnValueHandler> returnValueHandlers = this.requestMappingHandlerAdapter.getReturnValueHandlers();
|
||||||
|
Iterator<HandlerMethodReturnValueHandler> iterator = returnValueHandlers.iterator();
|
||||||
|
List<HandlerMethodReturnValueHandler> newProcessors = new ArrayList<>();
|
||||||
|
while (iterator.hasNext()) {
|
||||||
|
HandlerMethodReturnValueHandler next = iterator.next();
|
||||||
|
//在controller中直接返回map,不被默认的MapMethodProcessor拦截
|
||||||
|
if (next instanceof MapMethodProcessor ||
|
||||||
|
//在controller中直接返回String,不被默认的ViewNameMethodReturnValueHandler拦截
|
||||||
|
next instanceof ViewNameMethodReturnValueHandler) {
|
||||||
|
} else {
|
||||||
|
newProcessors.add(next);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.requestMappingHandlerAdapter.setReturnValueHandlers(newProcessors);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addReturnValueHandlers(List<HandlerMethodReturnValueHandler> returnValueHandlers) {
|
||||||
|
ResponseJsonMethodReturnValueHandler responseJsonMethodReturnValueHandler = new ResponseJsonMethodReturnValueHandler();
|
||||||
|
responseJsonMethodReturnValueHandler.afterPropertiesSet();
|
||||||
|
returnValueHandlers.add(responseJsonMethodReturnValueHandler);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void extendHandlerExceptionResolvers(List<HandlerExceptionResolver> exceptionResolvers) {
|
||||||
|
ResponseJsonExceptionResolver responseJsonExceptionResolver = new ResponseJsonExceptionResolver();
|
||||||
|
try {
|
||||||
|
responseJsonExceptionResolver.afterPropertiesSet();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
exceptionResolvers.add(responseJsonExceptionResolver);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
||||||
|
this.applicationContext = applicationContext;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
ServletContextListener listener1() {
|
||||||
|
return new ServletContextListener() {
|
||||||
|
@Override
|
||||||
|
public void contextInitialized(ServletContextEvent sce) {
|
||||||
|
requestMappingHandlerAdapter = applicationContext.getBean(RequestMappingHandlerAdapter.class);
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void contextDestroyed(ServletContextEvent sce) {
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -37,4 +37,18 @@
|
|||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<layers>
|
||||||
|
<enabled>true</enabled>
|
||||||
|
</layers>
|
||||||
|
<skip>false</skip>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@@ -66,6 +66,10 @@ rocketmq.producer.group=PID_handeTest
|
|||||||
spring.main.allow-circular-references=true
|
spring.main.allow-circular-references=true
|
||||||
spring.login.security.csrf=false
|
spring.login.security.csrf=false
|
||||||
|
|
||||||
|
spring.main.allow-bean-definition-overriding=true
|
||||||
|
spring.mvc.pathmatch.matching-strategy=ant_path_matcher
|
||||||
|
|
||||||
|
|
||||||
#elasticsearch
|
#elasticsearch
|
||||||
#essql.hosts=${OPENSEARCH_HOST:10.0.2.221,10.0.2.222,10.0.2.223}
|
#essql.hosts=${OPENSEARCH_HOST:10.0.2.221,10.0.2.222,10.0.2.223}
|
||||||
#essql.port=9200
|
#essql.port=9200
|
||||||
|
|||||||
@@ -52,6 +52,12 @@ rocketmq.consumerGroup=CID_handeTest
|
|||||||
rocketmq.tag=*
|
rocketmq.tag=*
|
||||||
rocketmq.producer.group=PID_handeTest
|
rocketmq.producer.group=PID_handeTest
|
||||||
|
|
||||||
|
spring.main.allow-circular-references=true
|
||||||
|
spring.login.security.csrf=false
|
||||||
|
|
||||||
|
spring.main.allow-bean-definition-overriding=true
|
||||||
|
spring.mvc.pathmatch.matching-strategy=ant_path_matcher
|
||||||
|
|
||||||
#elasticsearch
|
#elasticsearch
|
||||||
#essql.hosts=${OPENSEARCH_HOST}
|
#essql.hosts=${OPENSEARCH_HOST}
|
||||||
#essql.port=9200
|
#essql.port=9200
|
||||||
|
|||||||
@@ -53,6 +53,12 @@ rocketmq.consumerGroup=CID_handeTest
|
|||||||
rocketmq.tag=*
|
rocketmq.tag=*
|
||||||
rocketmq.producer.group=PID_handeTest
|
rocketmq.producer.group=PID_handeTest
|
||||||
|
|
||||||
|
spring.main.allow-circular-references=true
|
||||||
|
spring.login.security.csrf=false
|
||||||
|
|
||||||
|
spring.main.allow-bean-definition-overriding=true
|
||||||
|
spring.mvc.pathmatch.matching-strategy=ant_path_matcher
|
||||||
|
|
||||||
#elasticsearch
|
#elasticsearch
|
||||||
#essql.hosts=${OPENSEARCH_HOST:10.0.2.221,10.0.2.222,10.0.2.223}
|
#essql.hosts=${OPENSEARCH_HOST:10.0.2.221,10.0.2.222,10.0.2.223}
|
||||||
#essql.port=9200
|
#essql.port=9200
|
||||||
|
|||||||
@@ -75,6 +75,11 @@
|
|||||||
<vs.debug.version>1.0.0-SNAPSHOT</vs.debug.version>
|
<vs.debug.version>1.0.0-SNAPSHOT</vs.debug.version>
|
||||||
<vs.mock.spring>1.0.0-SNAPSHOT</vs.mock.spring>
|
<vs.mock.spring>1.0.0-SNAPSHOT</vs.mock.spring>
|
||||||
<toco.version>1.0.0-SNAPSHOT</toco.version>
|
<toco.version>1.0.0-SNAPSHOT</toco.version>
|
||||||
|
<log4j.version>2.23.1</log4j.version>
|
||||||
|
<org.hibernate.core>5.5.7.Final</org.hibernate.core>
|
||||||
|
<ox.sprintboot.web.starter.version>1.0-SNAPSHOT</ox.sprintboot.web.starter.version>
|
||||||
|
<ox.basidc.common>1.0-SNAPSHOT</ox.basidc.common>
|
||||||
|
<vs.sqlmapper.spring>1.0.0-SNAPSHOT</vs.sqlmapper.spring>
|
||||||
</properties>
|
</properties>
|
||||||
<dependencyManagement>
|
<dependencyManagement>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
@@ -395,6 +400,30 @@
|
|||||||
</dependencies>
|
</dependencies>
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-enforcer-plugin</artifactId>
|
||||||
|
<version>3.4.1</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>enforce</id>
|
||||||
|
<goals>
|
||||||
|
<goal>enforce</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<rules>
|
||||||
|
<requireJavaVersion>
|
||||||
|
<version>[11.0,21.0)</version>
|
||||||
|
</requireJavaVersion>
|
||||||
|
<requireMavenVersion>
|
||||||
|
<version>3.8</version>
|
||||||
|
</requireMavenVersion>
|
||||||
|
</rules>
|
||||||
|
<fail>true</fail>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-resources-plugin</artifactId>
|
<artifactId>maven-resources-plugin</artifactId>
|
||||||
@@ -403,6 +432,13 @@
|
|||||||
<encoding>UTF-8</encoding>
|
<encoding>UTF-8</encoding>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<skip>true</skip>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
<modules>
|
<modules>
|
||||||
|
|||||||
Reference in New Issue
Block a user