完善springmvc demo

taobao_model
tanghc 5 years ago
parent e8e34f0137
commit 801b5f1fd4
  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.mapping.ApiMappingHandlerMapping;
import com.gitee.sop.servercommon.message.ServiceErrorFactory;
import com.gitee.sop.servercommon.param.SopHandlerMethodArgumentResolver;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;
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 javax.annotation.PostConstruct;
@ -25,6 +27,8 @@ public class SpringMvcServiceConfiguration {
static {
System.setProperty(ServiceContext.SOP_MVC, "true");
// 默认版本号为1.0
ServiceConfig.getInstance().setDefaultVersion("1.0");
}
public SpringMvcServiceConfiguration() {
@ -33,6 +37,9 @@ public class SpringMvcServiceConfiguration {
private ApiMappingHandlerMapping apiMappingHandlerMapping = new ApiMappingHandlerMapping();
@Autowired
private RequestMappingHandlerAdapter requestMappingHandlerAdapter;
@Autowired
private Environment environment;
@ -72,7 +79,8 @@ public class SpringMvcServiceConfiguration {
* spring容器加载完毕后执行
*/
protected void doAfter() {
SopHandlerMethodArgumentResolver sopHandlerMethodArgumentResolver = ServiceConfig.getInstance().getMethodArgumentResolver();
sopHandlerMethodArgumentResolver.setRequestMappingHandlerAdapter(requestMappingHandlerAdapter);
}
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.ServiceContext;
import com.gitee.sop.servercommon.util.OpenUtil;
import org.apache.commons.lang.StringUtils;
import org.springframework.core.PriorityOrdered;
import org.springframework.util.StringValueResolver;
import org.springframework.web.servlet.mvc.condition.RequestCondition;
@ -30,7 +29,7 @@ public class ApiMappingHandlerMapping extends RequestMappingHandlerMapping imple
StringValueResolver valueResolver = null;
if (apiMapping != null) {
String version = apiMapping.version();
if (StringUtils.isBlank(version)) {
if ("".equals(version)) {
version = ServiceConfig.getInstance().getDefaultVersion();
}
valueResolver = new ApiMappingStringValueResolverVersion(version);

Loading…
Cancel
Save