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 1af76843..7da6a510 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
@@ -1,26 +1,9 @@
package com.gitee.sop.servercommon.configuration;
-import com.gitee.sop.servercommon.bean.ServiceConfig;
-import com.gitee.sop.servercommon.param.SopHandlerMethodArgumentResolver;
-import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter;
-
/**
* 具备支付宝开放平台服务提供能力
* @author tanghc
*/
public class AlipayServiceConfiguration extends BaseServiceConfiguration {
- static {
- // 默认版本号为1.0
- ServiceConfig.getInstance().setDefaultVersion("1.0");
- }
-
-
- @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 aadcd944..dd0405ed 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
@@ -3,18 +3,19 @@ package com.gitee.sop.servercommon.configuration;
import com.gitee.sop.servercommon.bean.ServiceConfig;
import com.gitee.sop.servercommon.interceptor.ServiceContextInterceptor;
import com.gitee.sop.servercommon.message.ServiceErrorFactory;
+import com.gitee.sop.servercommon.param.SopHandlerMethodArgumentResolver;
import com.gitee.sop.servercommon.route.ServiceRouteController;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeansException;
+import org.springframework.beans.factory.config.BeanPostProcessor;
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;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
+import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter;
import javax.annotation.PostConstruct;
import java.nio.charset.StandardCharsets;
@@ -24,19 +25,26 @@ import java.util.List;
* @author tanghc
*/
@Slf4j
-public class SpringmvcConfiguration implements WebMvcConfigurer, ApplicationContextAware {
+public class SpringmvcConfiguration implements WebMvcConfigurer, BeanPostProcessor {
public static final String METADATA_SERVER_CONTEXT_PATH = "server.servlet.context-path";
- private ApplicationContext applicationContext;
+ static {
+ ServiceConfig.getInstance().setDefaultVersion("1.0");
+ }
public SpringmvcConfiguration() {
ServiceConfig.getInstance().getI18nModules().add("i18n/isp/bizerror");
}
@Override
- public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
- this.applicationContext = applicationContext;
+ public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
+ if (bean instanceof RequestMappingHandlerAdapter) {
+ RequestMappingHandlerAdapter requestMappingHandlerAdapter = (RequestMappingHandlerAdapter) bean;
+ SopHandlerMethodArgumentResolver sopHandlerMethodArgumentResolver = ServiceConfig.getInstance().getMethodArgumentResolver();
+ sopHandlerMethodArgumentResolver.setRequestMappingHandlerAdapter(requestMappingHandlerAdapter);
+ }
+ return bean;
}
@Override
@@ -96,7 +104,4 @@ public class SpringmvcConfiguration implements WebMvcConfigurer, ApplicationCont
ServiceErrorFactory.initMessageSource(ServiceConfig.getInstance().getI18nModules());
}
- public ApplicationContext getApplicationContext() {
- return applicationContext;
- }
}
diff --git a/sop-example/sop-springmvc/src/main/java/com/gitee/app/config/OpenServiceConfig.java b/sop-example/sop-springmvc/src/main/java/com/gitee/app/config/OpenServiceConfig.java
index f9ddde68..3ff8e33b 100644
--- a/sop-example/sop-springmvc/src/main/java/com/gitee/app/config/OpenServiceConfig.java
+++ b/sop-example/sop-springmvc/src/main/java/com/gitee/app/config/OpenServiceConfig.java
@@ -6,7 +6,6 @@ import com.alibaba.nacos.api.naming.NamingService;
import com.alibaba.nacos.api.naming.pojo.Instance;
import com.alibaba.nacos.client.naming.utils.NetUtils;
import com.alibaba.nacos.spring.context.annotation.discovery.EnableNacosDiscovery;
-import com.gitee.sop.servercommon.bean.ServiceConfig;
import com.gitee.sop.servercommon.configuration.SpringmvcConfiguration;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
@@ -27,10 +26,6 @@ public class OpenServiceConfig extends SpringmvcConfiguration {
public static final String SERVER_PORT = "server.port";
public static final String METADATA_TIME_STARTUP = "server.startup-time";
- static {
- ServiceConfig.getInstance().setDefaultVersion("1.0");
- }
-
@Value("${spring.application.name}")
private String serviceId;
@Value("${server.port}")
diff --git a/sop-example/sop-springmvc/src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml b/sop-example/sop-springmvc/src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml
index e8140fce..b5893103 100644
--- a/sop-example/sop-springmvc/src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml
+++ b/sop-example/sop-springmvc/src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml
@@ -31,12 +31,7 @@
-
-
-
-
-
-
+