hrm项目总结一

1.搭建父模块 hrm-parent

1.配置pom

<!--springboot仲裁中心-->
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.5.RELEASE</version>
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
        <spring-cloud.version>Finchley.SR1</spring-cloud.version>
    </properties>

    <!-- 管理springcloud的版本-->
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

2.搭建中间模块 hrm-support-parent

什么都不用做

3.搭建eureka

1.配置pom

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
        </dependency>
    </dependencies>

    <!--    间接继承parent不需要指定执行的入口类,和repackage-->
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

2.配置yml

application.yml

spring:
  application:
    name: hrm-eureka

bootstrap.yml

spring:
  application:
    name: hrm-eureka
server:
  port: 1010
eureka:
  instance:
    hostname: localhost
  client:
    registerWithEureka: false
    fetchRegistry: false
    serviceUrl:
      defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/ #单机配置

3.写入口类

@SpringBootApplication
@EnableEurekaServer
public class Eureka1010Application {
    public static void main(String[] args) {
        SpringApplication.run(Eureka1010Application.class,args);
    }

}

3.搭建config server

1.创建码云库

在这里插入图片描述

2.构建一个能够提示额配置库

建立假的springboot项目
1.配置pom

<!--springboot仲裁中心-->
 <parent>
     <groupId>org.springframework.boot</groupId>
     <artifactId>spring-boot-starter-parent</artifactId>
     <version>2.0.5.RELEASE</version>
 </parent>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

2.yml

spring:
  profiles:
    active:
      - dev
---
server:
  port: 3355
spring:
  profiles: dev #开发环境
  application:
    name: MICROSERVICE-USER-DEV
---
server:
  port: 3355
spring:
  profiles: test #测试环境
  application:
    name: MICROSERVICE-USER-TEST

3.把配置库项目初始化到码云,并且删除本地,从码云进行导入。

3.在中间模块下面创建configServer模块

1.配置pom

  <!--springboot支持-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
        </dependency>

        <!--eureka客户端-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>
        <!--配置中心支持-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-config-server</artifactId>
        </dependency>

2.yml

server:
  port: 1020
eureka:
  client:
    service-url:
      defaultZone: http://localhost:1010/eureka
  instance:
    prefer-ip-address: true
spring:
  application:
    name: hrm-config-server
  cloud:
    config:
      server:
        git:
          uri: https://gitee.com/qyhdd/hrm-config.git
          username: git账号
          password: git密码
          search-paths: src/main/resources # 如果不是在根路径下面需要加搜索地址

3.入口类

@SpringBootApplication
@EnableEurekaClient
@EnableConfigServer
public class ConfigServer1020Application {
    public static void main(String[] args) {
        SpringApplication.run(ConfigServer1020Application.class,args);
    }
}

4.搭建Zuul GateWay

1.配置pom

 <!-- springBoot支持 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <!-- spring boot 测试 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
        </dependency>
        <!-- Eureka 客户端依赖 -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>
       
         <!-- zuul支持-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-zuul</artifactId>
        </dependency>
       <!--配置中心支持-->
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-config</artifactId>
</dependency>

2.配置yml

application.yml

spring:
  application:
    name: zuul-gateway

bootstap

spring:
  profiles:
    active: dev
  cloud:
    config:
      name: application-zuul
      profile: ${spring.profiles.active} #环境 java -jar -D xxx jar
      label: master #分支
      discovery: #configserver集群
        enabled: true #从eureka上面找配置服务
        service-id: hrm-config-server #指定服务名
        #uri: http://127.0.0.1:1299 #配置服务器 单机配置
eureka: #eureka不能放到远程配置中
  client:
      service-url:
        defaultZone: http://localhost:1010/eureka  #告诉服务提供者要把服务注册到哪儿 #单机环境
  instance:
      prefer-ip-address: true #显示客户端真实ip

3.入口类

@SpringBootApplication
@EnableZuulProxy
public class Zuul1030Application {
    public static void main(String[] args) {
        SpringApplication.run(Zuul1030Application.class,args);
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值