Browse Source

model类提交

chenweida 7 years ago
parent
commit
04c89d470f

+ 5 - 7
svr-configuration/pom.xml

@ -22,17 +22,15 @@
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-eureka-server</artifactId>
            <artifactId>spring-cloud-starter-eureka</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>ch.qos.logback</groupId>
                    <artifactId>logback-classic</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
    </dependencies>

+ 16 - 0
svr-configuration/src/main/java/com.yihu.jw/Application.java

@ -0,0 +1,16 @@
package com.yihu.jw;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.config.server.EnableConfigServer;
/**
 * Created by chenweida on 2017/5/14.
 */
@SpringBootApplication
@EnableConfigServer
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

+ 8 - 10
svr-configuration/src/main/resources/application.yml

@ -4,25 +4,23 @@ server:
management:
  port: ${server.port}
security:
  user:
    password: configuration
info:
  app:
    name: ConfigurationService
    description: EHR平台全局配置服务
    description: 全局配置服务
    version: 1.0.0
---
spring:
  profiles: dev
eureka:
  instance:
    ip-address: 127.0.0.1:8761
    #ip-address: 192.168.1.221:8761
    prefer-ip-address: false
    ip-address: http://${discovery.name}:${discovery.password}@127.0.0.1:8761
    prefer-ip-address: true
---
spring:
@ -30,7 +28,7 @@ spring:
eureka:
  instance:
    ip-address: 172.19.103.73:8761
    ip-address: http://${discovery.name}:${discovery.password}@172.19.103.73:8761
    prefer-ip-address: true
---
@ -39,5 +37,5 @@ spring:
eureka:
  instance:
    ip-address: 11.1.2.21:8761
    ip-address: http://${discovery.name}:${discovery.password}@11.1.2.21:8761
    prefer-ip-address: true

+ 8 - 0
svr-configuration/src/main/resources/bootstrap.yml

@ -2,6 +2,14 @@ spring:
  application:
    name: svr-configurations
security:
  user:
    name: jw
    password:  jkzlJwConfiguration
---
spring:
  profiles: dev

+ 4 - 0
svr-discovery/pom.xml

@ -23,6 +23,10 @@
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-logging</artifactId>
        </dependency>
        <!--给 eurika界面添加账号密码验证-->
        <dependency>
            <groupId>org.springframework.boot</groupId>

+ 4 - 4
svr-discovery/src/main/resources/application.yml

@ -11,8 +11,8 @@ eureka:
    register-with-eureka: false #是否注册到eurika
    registry-fetch-interval-seconds: 30 #定期的更新客户端的服务清单 30秒更新一次
#    fetch-registry: false
    serviceUrl:
      defaultZone: http://user:123456@127.0.0.1:8761/eureka/
#    serviceUrl:
#      defaultZone: http://user:123456@127.0.0.1:8761/eureka/
#eurika界面的账号密码
@ -20,8 +20,8 @@ security:
  basic:
    enabled: true
  user:
    name: user
    password: 123456
    name: jw
    password: jkzlJwDiscovery
---

+ 44 - 1
svr-lib-parent-pom/pom.xml

@ -38,10 +38,19 @@
        <version.springCloud.start>1.2.0.RELEASE</version.springCloud.start>
        <version.springBoot>1.5.3.RELEASE</version.springBoot>
        <version.mysql>5.1.38</version.mysql>
        <version.myCommon>1.0.0</version.myCommon>
    </properties>
    <!--dependencyManagement作用子配置不写版本默认继承父配置-->
    <dependencyManagement>
        <dependencies>
            <!--自己的封装 common -->
            <dependency>
                <groupId>com.yihu</groupId>
                <artifactId>common-swagger</artifactId>
                <version>${version.myCommon}</version>
            </dependency>
            <!--springCloud start-->
            <dependency>
                <groupId>org.springframework.cloud</groupId>
@ -68,13 +77,42 @@
                <artifactId>spring-cloud-starter-bus-amqp</artifactId>
                <version>${version.springCloud}</version>
            </dependency>
            <!--路由网关-->
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-zuul</artifactId>
                <version>${version.springCloud}</version>
            </dependency>
            <!--断路由-->
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-hystrix</artifactId>
                <version>${version.springCloud}</version>
            </dependency>
            <!--hystrix仪表盘-->
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-netflix-hystrix-dashboard</artifactId>
                <version>${version.springCloud}</version>
            </dependency>
            <!--配置服务客户端-->
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-config</artifactId>
                <version>${version.springCloud}</version>
            </dependency>
            <!--发现服务服务客户端-->
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-eureka</artifactId>
                <version>${version.springCloud}</version>
            </dependency>
            <!--收集集群中的数据-->
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-turbine</artifactId>
                <version>${version.springCloud}</version>
            </dependency>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-feign</artifactId>
@ -146,6 +184,11 @@
                <artifactId>spring-boot-starter-mail</artifactId>
                <version>${version.springBoot}</version>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-logging</artifactId>
                <version>${version.springBoot}</version>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-tomcat</artifactId>

+ 10 - 3
svr/svr-base/pom.xml

@ -17,7 +17,6 @@
        <dependency>
            <groupId>com.yihu</groupId>
            <artifactId>common-swagger</artifactId>
            <version>1.0.0</version>
        </dependency>
        <dependency>
@ -41,12 +40,20 @@
            <artifactId>spring-boot-starter-aop</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-eureka-server</artifactId>
            <artifactId>spring-cloud-starter-eureka</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-config</artifactId>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>

+ 2 - 5
svr/svr-base/src/main/java/com/yihu/jw/Application.java

@ -6,21 +6,18 @@ import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;
/**
 * Created by chenweida on 2017/5/10.
 * localhost:10020/refresh  刷新当个微服务的配置 可以在需要刷新的bean上面@RefreshScope
 */
@SpringBootApplication
@EnableDiscoveryClient//服务注册到发现服务
public class Application {
    @Bean
    @LoadBalanced
    public RestTemplate restTemplate(){
        return new RestTemplate();
    }
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

+ 7 - 21
svr/svr-base/src/main/resources/application.yml

@ -1,29 +1,10 @@
##如果有配置服务的话,远程服务器和本地服务器配置不一致的情况下,优先远程的为主
server:
  port: 10020
spring:
  application:
    name:  svr-user  ##注册到发现服务的id 如果id一样 eurika会自动做负载
  cloud:
    config:
      enabled: false    ##是否加入配置服务
eureka:
  client:
    serviceUrl:
      #http://账号:密码@127.0.0.1:8761/eureka/
      defaultZone: http://user:123456@127.0.0.1:8761/eureka/
    healthcheck:
      enabled: true #启动监控检查
  instance:
    #eurika使用IP不使用host
    prefer-ip-address: true
    #定制化在eurika中显示的名称
    instance-id: ${spring.application.name}:${spring.application.instance_id:${server.port}}
spring:
  datasource:
    driver-class-name: com.mysql.jdbc.Driver
    max-active: 50
@ -47,7 +28,10 @@ hibernate:
  dialect: org.hibernate.dialect.MySQL5Dialect
  show_sql: true
  ejb:
    naming_strategy: org.hibernate.cfg.ImprovedNamingStrategy
    naming_strategy: org.hibernate.cfg.ImprovedNamingStrategy #springJPA使用驼峰式
---
spring:
  profiles: dev
@ -58,10 +42,12 @@ spring:
    username: wlyy
    password: 123456
---
spring:
  profiles: test
---
spring:
  profiles: prod

+ 26 - 0
svr/svr-base/src/main/resources/bootstrap.yml

@ -0,0 +1,26 @@
##优先读取 boostarap配置 然后在读取application。yml的配置
spring:
  application:
    name: svr-user
  #从发现服务里面取配置服务的信息
  cloud:
    config:
      username: jw
      password: jkzlJwConfiguration
      discovery:
        enabled: true ##开始发现服务
        service-id: svr-configurations ##配置服务的名字
eureka:
  client:
    serviceUrl:
      #http://账号:密码@127.0.0.1:8761/eureka/
      defaultZone: http://user:123456@127.0.0.1:8761/eureka/
    healthcheck:
      enabled: true #启动监控检查
  instance:
    #eurika使用IP不使用host
    prefer-ip-address: true
    #定制化在eurika中显示的名称
    instance-id: ${spring.application.name}:${spring.application.instance_id:${server.port}}

+ 13 - 2
web-gateway/pom.xml

@ -17,7 +17,6 @@
        <dependency>
            <groupId>com.yihu</groupId>
            <artifactId>common-swagger</artifactId>
            <version>1.0.0</version>
        </dependency>
        <dependency>
@ -44,7 +43,11 @@
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-eureka-server</artifactId>
            <artifactId>spring-cloud-starter-eureka</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-config</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
@ -54,5 +57,13 @@
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-hystrix</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-netflix-hystrix-dashboard</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-zuul</artifactId>
        </dependency>
    </dependencies>
</project>

+ 8 - 1
web-gateway/src/main/java/com/yihu/jw/Application.java

@ -8,15 +8,22 @@ import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfigurat
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.netflix.feign.EnableFeignClients;
import org.springframework.cloud.netflix.hystrix.EnableHystrix;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;
/**
 * Created by chenweida on 2017/5/10.
 */
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class})
//@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class})
@SpringBootApplication
@EnableDiscoveryClient//服务注册到发现服务
@EnableFeignClients //声名式的客户端
@EnableHystrix //启动断路器
@EnableHystrixDashboard //启动Hystrix仪表盘(监控数据)
@EnableZuulProxy //启动zuul代理 路由
public class Application {
    public static void main(String[] args) {

+ 16 - 0
web-gateway/src/main/java/com/yihu/jw/controller/PatientController.java

@ -1,5 +1,7 @@
package com.yihu.jw.controller;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import com.yihu.jw.fegin.PatientFegin;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@ -8,6 +10,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.context.annotation.SessionScope;
/**
 * Created by chenweida on 2017/5/10.
@ -21,8 +24,21 @@ public class PatientController {
    @ApiOperation(value = "根据code查找患者")
    @GetMapping(value = "findByCode")
    //配置HystrixProperty 则调用的方法和fallback是同一个线程 否则就不是
    //@HystrixCommand(fallbackMethod = "findByCodeFallback",commandProperties = @HystrixProperty(name = "execution.isolation.strategy",value = "SEMAPHORE"))
    @HystrixCommand(fallbackMethod = "findByCodeFallback" )
    public String findByCode(
            @ApiParam(name = "code", value = "患者code", required = true) @RequestParam(value = "code", required = true) String code) {
        return patientFegin.findByCode(code);
    }
//    /**
//     * 参数要一致 返回值类型也要一致
//     *
//     * @param code
//     * @return
//     */
//    public String findByCodeFallback(String code) {
//        return "";
//    }
}

+ 7 - 2
web-gateway/src/main/java/com/yihu/jw/fegin/PatientFegin.java

@ -1,5 +1,6 @@
package com.yihu.jw.fegin;
import com.yihu.jw.fegin.fallback.PatientFeginFallback;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.cloud.netflix.feign.FeignClient;
@ -11,11 +12,15 @@ import org.springframework.web.bind.annotation.RequestParam;
/**
 * Created by chenweida on 2017/5/10.
 */
@FeignClient("svr-user")// 值是eurika的实例名字
@FeignClient(
        name = "svr-user", // name值是eurika的实例名字
        fallback = PatientFeginFallback.class// fallback是请求超时或者错误的回调函数
//        ,configuration =   //可以配置当个fegin的配置 例如禁用单个feign的hystrix
    )
@RequestMapping("/patient")
public interface PatientFegin {
    @RequestMapping(value = "/findByCode",method = RequestMethod.GET)
    @RequestMapping(value = "/findByCode", method = RequestMethod.GET)
    public String findByCode(@RequestParam(value = "code", required = true) String code);
}

+ 16 - 0
web-gateway/src/main/java/com/yihu/jw/fegin/fallback/PatientFeginFallback.java

@ -0,0 +1,16 @@
package com.yihu.jw.fegin.fallback;
import com.yihu.jw.fegin.PatientFegin;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestParam;
/**
 * Created by chenweida on 2017/5/13.
 */
@Component
public class PatientFeginFallback implements PatientFegin{
    @Override
    public String findByCode(@RequestParam(value = "code", required = true) String code) {
        return "";
    }
}

+ 27 - 0
web-gateway/src/main/resources/application.yml

@ -1,3 +1,5 @@
##如果有配置服务的话,远程服务器和本地服务器配置不一致的情况下,优先远程的为主
server:
server:
  port: 8088
@ -26,6 +28,31 @@ eureka:
hystrix:
  metrics:
    polling-interval-ms: 20000 ##熔断间隔时间 默认是2秒 
#zuul 默认会代理所有的微服务  路径 /{appliction.name}/**
zuul:
  ignored-services: '*'  ##忽略全部的代理  忽略单个微服务   ignored-services: svr-user 多个逗号分割
  routes:
    svr-user: /user/**  ##svr-user方向代理到/user下多层级的路径
#    svr-user:    这种方式和  svr-user: /user/**  一样  svr-user可以随便写 唯一即可
#      path: /user/**  path是代理后的路径
#      serviceId: svr-user  serviceId是微服务name
#   svr-user: 这种方式和 上面一样 就是serviceId改成具体的url 但是这种配置方法不能利用eurika的负载均衡
#     path: /user/**
#     url: http://localhost:10020/
#svr-user: 这边是微服务ID  配置负载均衡
#  ribbon:
#    listOfService: http://localhost:10020/,http://localhost:10021/
---
spring:

+ 36 - 0
web-gateway/src/main/resources/bootstrap.yml

@ -0,0 +1,36 @@
##优先读取 boostarap配置 然后在读取application。yml的配置
##boostarap一般是配置基本不会修改的配置
spring:
  application:
    name: web-gateway  ##写这个配置的话 会先去服务器找web-gateway.yml的配置 没有的话就找application.yml
---
spring:
  profiles: dev
  cloud:
    config:
      username: jw
      password: jkzljw
      uri: http://127.0.0.1:1221
      #uri: http://192.168.1.221:1221
      label: dev
---
spring:
  profiles: test
  cloud:
    config:
      username: jw
      password: jkzljw
      uri: http://172.19.103.73:1221
      label: dev
---
spring:
  profiles: prod
  cloud:
    config:
      username: jw
      password: jkzljw
      uri: http://11.1.2.21:1221
      label: master