| 
                         先看目录结构: 
  
一共有 5 个模块,其中 common 是纯 Java 代码用于各模块公共代码的提取,剩下四个每个是一个独立的微服务模块,所以我们要部署 eureka  、user、education、gateway 四个模块,也就是最后会运行四个独立的 Docker 容器。 
具体的业务逻辑就不做过多说明了,本文只讲部署。 
配置文件 application.yml
为了本地调试和服务器部署互不影响,我们把原来的 application.yml 拆分为三个文件: 
    - application.yml:总配置,指定应该用下面哪个配置
 
    - application-dev.yml:开发环境配置
 
    - application-pro.yml:生成环境配置
 
 
另外为了方便,把 Dockerfile 也放到同级目录下。如图: 
  
下面是三个配置文件的代码: 
- spring: 
 - profiles: 
 - active: pro 
 -  
 -  
 -  
 - eureka: 
 - client: 
 - service-url: 
 -   defaultZone: http://localhost:8761/eureka/ 
 - instance: 
 - prefer-ip-address: true 
 -  
 - server: 
 - port: 8899 
 -  
 - spring: 
 - application: 
 - name: education 
 - datasource: 
 - driver-class-name: com.mysql.jdbc.Driver 
 - username: root 
 - password: 123456 
 - url: jdbc:mysql://127.0.0.1/edu?characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai 
 - jpa: 
 - show-sql: true 
 - # 如果字段值为null则不返回 
 - jackson: 
 - default-property-inclusion: non_null 
 -  
 - rabbitmq: 
 - host: localhost 
 - port: 5672 
 - username: guest 
 - password: guest 
 -  
 - redis: 
 - port: 6379 
 - database: 0 
 - host: 127.0.0.1 
 - password: 
 - jedis: 
 -   pool: 
 -     max-active: 8 
 -     max-wait: -1ms 
 -     max-idle: 8 
 -     min-idle: 0 
 - timeout: 5000ms 
 -  
 
 -  
 - eureka: 
 - client: 
 - service-url: 
 -   defaultZone: ${SPRING-CLOUD-EUREKA-ZONE} 
 - instance: 
 - prefer-ip-address: true 
 -  
 - server: 
 - port: 8899 
 -  
 - spring: 
 - application: 
 - name: education 
 - datasource: 
 - driver-class-name: com.mysql.jdbc.Driver 
 - username: root 
 - password: 123456 
 - url: jdbc:mysql://${SPRING-CLOUD-MYSQL-HOST}/${SPRING-CLOUD-DB-NAME}?characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai 
 - jpa: 
 - show-sql: true 
 - # 如果字段值为null则不返回 
 - jackson: 
 - default-property-inclusion: non_null 
 -  
 - rabbitmq: 
 - host: ${SPRING-CLOUD-RABBIT-MQ-HOST} 
 - port: 5672 
 - username: guest 
 - password: guest 
 -  
 - redis: 
 - port: 6379 
 - database: 0 
 - host: ${SPRING-CLOUD-REDIS-HOST} 
 - password: 
 - jedis: 
 -   pool: 
 -     max-active: 8 
 -     max-wait: -1ms 
 -     max-idle: 8 
 -     min-idle: 0 
 - timeout: 5000ms 
 
  
这个项目配置比较全,Redis、RabbitMQ、MySQL、JPA 都有配置。 
dev 跟 pro 的配置差不多,只是把 dev 中的 localhost 、127.0.0.1 这两个本地的地址,换成了诸如  ${SPRING-CLOUD-EUREKA-ZONE}、${SPRING-CLOUD-RABBIT-MQ-HOST} 等变量。                         (编辑:91站长网) 
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! 
                     |