diff --git a/changelog.md b/changelog.md index 0657a6a4..cfc42ddd 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,10 @@ # changelog +## 3.1.1 + +- 修复继承WebMvcConfigurationSupport导致的jackson序列化时间问题 +- 修复微服务接口返回void网关不会返回code和msg问题 + ## 3.1.0 - 新增路由监控功能 diff --git a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/filter/GatewayModifyResponseGatewayFilter.java b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/filter/GatewayModifyResponseGatewayFilter.java index 974a3a4c..aa248d9c 100644 --- a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/filter/GatewayModifyResponseGatewayFilter.java +++ b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/filter/GatewayModifyResponseGatewayFilter.java @@ -59,6 +59,8 @@ public class GatewayModifyResponseGatewayFilter implements GlobalFilter, Ordered //TODO: flux or mono Mono modifiedBody = clientResponse.bodyToMono(inClass) + // 修复微服务接口返回void网关不会返回code和msg问题 + .switchIfEmpty(Mono.just("")) .flatMap(originalBody -> { // 合并微服务传递过来的结果,变成最终结果 ResultExecutor resultExecutor = ApiContext.getApiConfig().getGatewayResultExecutor(); diff --git a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/configuration/BaseServiceConfiguration.java b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/configuration/BaseServiceConfiguration.java index 2520b137..84534a9d 100644 --- a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/configuration/BaseServiceConfiguration.java +++ b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/configuration/BaseServiceConfiguration.java @@ -9,13 +9,14 @@ import com.gitee.sop.servercommon.message.ServiceErrorFactory; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.autoconfigure.web.servlet.WebMvcRegistrations; import org.springframework.context.annotation.Bean; import org.springframework.core.env.Environment; import org.springframework.http.converter.HttpMessageConverter; import org.springframework.http.converter.StringHttpMessageConverter; import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; -import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; import javax.annotation.PostConstruct; @@ -26,7 +27,7 @@ import java.util.List; * @author tanghc */ @Slf4j -public class BaseServiceConfiguration extends WebMvcConfigurationSupport { +public class BaseServiceConfiguration implements WebMvcConfigurer, WebMvcRegistrations { public BaseServiceConfiguration() { ServiceConfig.getInstance().getI18nModules().add("i18n/isp/bizerror"); @@ -38,8 +39,7 @@ public class BaseServiceConfiguration extends WebMvcConfigurationSupport { private Environment environment; @Override - protected void addResourceHandlers(ResourceHandlerRegistry registry) { - super.addResourceHandlers(registry); + public void addResourceHandlers(ResourceHandlerRegistry registry) { // 支持swagger-bootstrap-ui首页 registry.addResourceHandler("doc.html").addResourceLocations("classpath:/META-INF/resources/"); // 支持默认swagger @@ -48,14 +48,13 @@ public class BaseServiceConfiguration extends WebMvcConfigurationSupport { } @Override - protected void addInterceptors(InterceptorRegistry registry) { + public void addInterceptors(InterceptorRegistry registry) { // 添加拦截器 registry.addInterceptor(new ServiceContextInterceptor()); - super.addInterceptors(registry); } @Override - protected void extendMessageConverters(List> converters) { + public void extendMessageConverters(List> converters) { // 解决controller返回字符串中文乱码问题 for (HttpMessageConverter converter : converters) { if (converter instanceof StringHttpMessageConverter) { @@ -69,7 +68,7 @@ public class BaseServiceConfiguration extends WebMvcConfigurationSupport { * @return 返回RequestMappingHandlerMapping */ @Override - protected RequestMappingHandlerMapping createRequestMappingHandlerMapping() { + public RequestMappingHandlerMapping getRequestMappingHandlerMapping() { return apiMappingHandlerMapping; } diff --git a/sop-example/sop-book/sop-book-web/src/main/java/com/gitee/sop/bookweb/config/OpenServiceConfig.java b/sop-example/sop-book/sop-book-web/src/main/java/com/gitee/sop/bookweb/config/OpenServiceConfig.java index 2a4ce64a..a84ddea8 100644 --- a/sop-example/sop-book/sop-book-web/src/main/java/com/gitee/sop/bookweb/config/OpenServiceConfig.java +++ b/sop-example/sop-book/sop-book-web/src/main/java/com/gitee/sop/bookweb/config/OpenServiceConfig.java @@ -3,7 +3,6 @@ package com.gitee.sop.bookweb.config; import com.gitee.sop.servercommon.configuration.AlipayServiceConfiguration; import com.gitee.sop.servercommon.swagger.SwaggerSupport; import org.springframework.context.annotation.Configuration; -import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; import springfox.documentation.swagger2.annotations.EnableSwagger2; /** @@ -13,15 +12,6 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2; @Configuration public class OpenServiceConfig extends AlipayServiceConfiguration { - @Override - protected void addResourceHandlers(ResourceHandlerRegistry registry) { - super.addResourceHandlers(registry); - registry.addResourceHandler("swagger-ui.html") - .addResourceLocations("classpath:/META-INF/resources/"); - registry.addResourceHandler("/webjars/**") - .addResourceLocations("classpath:/META-INF/resources/webjars/"); - } - // 开启文档 @Configuration @EnableSwagger2