Merge branch 'master' into eureka

eureka
tanghc 5 years ago
commit 4cc900d83d
  1. 10
      sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/configuration/SpringMvcServiceConfiguration.java
  2. 3
      sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/mapping/ApiMappingHandlerMapping.java

@ -6,12 +6,14 @@ import com.gitee.sop.servercommon.manager.EnvironmentContext;
import com.gitee.sop.servercommon.manager.ServiceRouteController; import com.gitee.sop.servercommon.manager.ServiceRouteController;
import com.gitee.sop.servercommon.mapping.ApiMappingHandlerMapping; import com.gitee.sop.servercommon.mapping.ApiMappingHandlerMapping;
import com.gitee.sop.servercommon.message.ServiceErrorFactory; import com.gitee.sop.servercommon.message.ServiceErrorFactory;
import com.gitee.sop.servercommon.param.SopHandlerMethodArgumentResolver;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary; import org.springframework.context.annotation.Primary;
import org.springframework.core.env.Environment; import org.springframework.core.env.Environment;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
@ -25,6 +27,8 @@ public class SpringMvcServiceConfiguration {
static { static {
System.setProperty(ServiceContext.SOP_MVC, "true"); System.setProperty(ServiceContext.SOP_MVC, "true");
// 默认版本号为1.0
ServiceConfig.getInstance().setDefaultVersion("1.0");
} }
public SpringMvcServiceConfiguration() { public SpringMvcServiceConfiguration() {
@ -33,6 +37,9 @@ public class SpringMvcServiceConfiguration {
private ApiMappingHandlerMapping apiMappingHandlerMapping = new ApiMappingHandlerMapping(); private ApiMappingHandlerMapping apiMappingHandlerMapping = new ApiMappingHandlerMapping();
@Autowired
private RequestMappingHandlerAdapter requestMappingHandlerAdapter;
@Autowired @Autowired
private Environment environment; private Environment environment;
@ -72,7 +79,8 @@ public class SpringMvcServiceConfiguration {
* spring容器加载完毕后执行 * spring容器加载完毕后执行
*/ */
protected void doAfter() { protected void doAfter() {
SopHandlerMethodArgumentResolver sopHandlerMethodArgumentResolver = ServiceConfig.getInstance().getMethodArgumentResolver();
sopHandlerMethodArgumentResolver.setRequestMappingHandlerAdapter(requestMappingHandlerAdapter);
} }
protected void initMessage() { protected void initMessage() {

@ -5,7 +5,6 @@ import com.gitee.sop.servercommon.annotation.ApiMapping;
import com.gitee.sop.servercommon.bean.ServiceConfig; import com.gitee.sop.servercommon.bean.ServiceConfig;
import com.gitee.sop.servercommon.bean.ServiceContext; import com.gitee.sop.servercommon.bean.ServiceContext;
import com.gitee.sop.servercommon.util.OpenUtil; import com.gitee.sop.servercommon.util.OpenUtil;
import org.apache.commons.lang.StringUtils;
import org.springframework.core.PriorityOrdered; import org.springframework.core.PriorityOrdered;
import org.springframework.util.StringValueResolver; import org.springframework.util.StringValueResolver;
import org.springframework.web.servlet.mvc.condition.RequestCondition; import org.springframework.web.servlet.mvc.condition.RequestCondition;
@ -30,7 +29,7 @@ public class ApiMappingHandlerMapping extends RequestMappingHandlerMapping imple
StringValueResolver valueResolver = null; StringValueResolver valueResolver = null;
if (apiMapping != null) { if (apiMapping != null) {
String version = apiMapping.version(); String version = apiMapping.version();
if (StringUtils.isBlank(version)) { if ("".equals(version)) {
version = ServiceConfig.getInstance().getDefaultVersion(); version = ServiceConfig.getInstance().getDefaultVersion();
} }
valueResolver = new ApiMappingStringValueResolverVersion(version); valueResolver = new ApiMappingStringValueResolverVersion(version);

Loading…
Cancel
Save