From c0e165f59b347769d0e7ab63b938dfd1db85f1f2 Mon Sep 17 00:00:00 2001 From: tanghc Date: Tue, 1 Dec 2020 13:58:17 +0800 Subject: [PATCH] 4.2.1 --- .../configuration/AlipayServiceConfiguration.java | 4 +--- .../configuration/SpringmvcConfiguration.java | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/configuration/AlipayServiceConfiguration.java b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/configuration/AlipayServiceConfiguration.java index 9525532b..1af76843 100644 --- a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/configuration/AlipayServiceConfiguration.java +++ b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/configuration/AlipayServiceConfiguration.java @@ -2,7 +2,6 @@ package com.gitee.sop.servercommon.configuration; import com.gitee.sop.servercommon.bean.ServiceConfig; import com.gitee.sop.servercommon.param.SopHandlerMethodArgumentResolver; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter; /** @@ -16,12 +15,11 @@ public class AlipayServiceConfiguration extends BaseServiceConfiguration { ServiceConfig.getInstance().setDefaultVersion("1.0"); } - @Autowired - private RequestMappingHandlerAdapter requestMappingHandlerAdapter; @Override protected void doAfter() { super.doAfter(); + RequestMappingHandlerAdapter requestMappingHandlerAdapter = getApplicationContext().getBean(RequestMappingHandlerAdapter.class); SopHandlerMethodArgumentResolver sopHandlerMethodArgumentResolver = ServiceConfig.getInstance().getMethodArgumentResolver(); sopHandlerMethodArgumentResolver.setRequestMappingHandlerAdapter(requestMappingHandlerAdapter); } diff --git a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/configuration/SpringmvcConfiguration.java b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/configuration/SpringmvcConfiguration.java index 4162f0f8..aadcd944 100644 --- a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/configuration/SpringmvcConfiguration.java +++ b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/configuration/SpringmvcConfiguration.java @@ -5,7 +5,10 @@ import com.gitee.sop.servercommon.interceptor.ServiceContextInterceptor; import com.gitee.sop.servercommon.message.ServiceErrorFactory; import com.gitee.sop.servercommon.route.ServiceRouteController; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.BeansException; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; import org.springframework.context.annotation.Bean; import org.springframework.http.converter.HttpMessageConverter; import org.springframework.http.converter.StringHttpMessageConverter; @@ -21,14 +24,21 @@ import java.util.List; * @author tanghc */ @Slf4j -public class SpringmvcConfiguration implements WebMvcConfigurer { +public class SpringmvcConfiguration implements WebMvcConfigurer, ApplicationContextAware { public static final String METADATA_SERVER_CONTEXT_PATH = "server.servlet.context-path"; + private ApplicationContext applicationContext; + public SpringmvcConfiguration() { ServiceConfig.getInstance().getI18nModules().add("i18n/isp/bizerror"); } + @Override + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { + this.applicationContext = applicationContext; + } + @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { // 支持swagger-bootstrap-ui首页 @@ -86,4 +96,7 @@ public class SpringmvcConfiguration implements WebMvcConfigurer { ServiceErrorFactory.initMessageSource(ServiceConfig.getInstance().getI18nModules()); } + public ApplicationContext getApplicationContext() { + return applicationContext; + } }