Browse Source

Merge branch 'dev' of chenweida/wlyy2.0 into dev

chenweida 7 years ago
parent
commit
1f4078551f

+ 4 - 0
web-gateway/pom.xml

@ -135,6 +135,10 @@
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-sleuth</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-ribbon</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-sleuth-zipkin</artifactId>

+ 10 - 0
web-gateway/src/main/java/com/yihu/jw/config/mvc/MvcConfig.java

@ -1,7 +1,11 @@
package com.yihu.jw.config.mvc;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
@ -28,4 +32,10 @@ public class MvcConfig extends WebMvcConfigurationSupport {
                .addResourceLocations("classpath:/META-INF/resources/webjars/");
    }
    @Bean
    @LoadBalanced
    // 添加负载均衡支持,很简单,只需要在RestTemplate上添加@LoadBalanced注解,那么RestTemplate即具有负载均衡的功能,如果不加@LoadBalanced注解的话,会报java.net.UnknownHostException:springboot-h2异常,此时无法通过注册到Eureka Server上的服务名来调用服务,因为RestTemplate是无法从服务名映射到ip:port的,映射的功能是由LoadBalancerClient来实现的。
    public RestTemplate restTemplate() {
        return new RestTemplate();
    }
}

+ 6 - 4
web-gateway/src/main/java/com/yihu/jw/controller/base/login/LoginContorller.java

@ -59,6 +59,10 @@ public class LoginContorller {
    private EmployFeign employFeign;
    @Value("${server.web-gateway-port}")
    private String port;
    @Autowired
    private RestTemplate restTemplate ;
    @Value("${spring.application.name}")
    private String appName;
    @PostMapping(value = BaseLoginRequestMapping.BaseLoginAccount.api_checkoutInfo, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "注册校验信息", notes = "注册校验姓名、身份证、医保卡号信息")
@ -155,15 +159,13 @@ public class LoginContorller {
            params.add("password", MD5.GetMD5Code(password+employMap.get("salt")));
            //设置http请求实体
            HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<MultiValueMap<String, String>>(params, headers);
            RestTemplate restTemplate = new RestTemplate();
            token = restTemplate.postForObject("http://localhost:"+port+"/authentication/form", requestEntity, String.class);
            token = restTemplate.postForObject("http://"+appName.toUpperCase()+"/authentication/form", requestEntity, String.class);
        }else{
            params.add("mobile", mobilePhone+","+saasId);
            params.add("sms", captcha);
            //设置http请求实体
            HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<MultiValueMap<String, String>>(params, headers);
            RestTemplate restTemplate = new RestTemplate();
            token = restTemplate.postForObject("http://localhost:"+port+"/authentication/mobile", requestEntity, String.class);
            token = restTemplate.postForObject("http://"+appName.toUpperCase()+"/authentication/mobile", requestEntity, String.class);
        }
        if(!StringUtils.isEmpty(token)){