nacos配置管理与服务发现

守給你的承諾、 提交于 2020-05-06 12:48:44

maven配置

父pom文件

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.ivan</groupId>
    <artifactId>pinellia</artifactId>
    <packaging>pom</packaging>
    <version>1.0.0-SNAPSHOT</version>
    <modules>
        <module>pinellia-common</module>
        <module>pinellia-service</module>
        <module>pinellia-service-api</module>
        <module>pinellia-auth</module>
        <module>pinellia-gateway</module>
    </modules>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.6.RELEASE</version>
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.version>1.8</java.version>
        <spring.cloud.version>Hoxton.SR4</spring.cloud.version>
        <spring.cloud.alibaba.version>2.1.1.RELEASE</spring.cloud.alibaba.version>
        <mysql.version>8.0.19</mysql.version>
        <mybatis.plus.version>3.3.0</mybatis.plus.version>
        <velocity.version>2.2</velocity.version>
        <hutool.version>5.3.2</hutool.version>
        <p6spy.version>3.8.7</p6spy.version>
        <swagger.version>2.9.2</swagger.version>
        <swagger.models.version>1.5.21</swagger.models.version>
        <knife4j.version>2.0.1</knife4j.version>
        <spring.boot.admin.version>2.2.0</spring.boot.admin.version>
        <jwt.version>0.9.1</jwt.version>
        <easy.excel.version>2.1.6</easy.excel.version>
        <common.version>1.0.0-SNAPSHOT</common.version>
    </properties>

    <dependencyManagement>
        <dependencies>
            <!--spring cloud-->
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring.cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>

            <!--spring cloud alibaba-->
            <dependency>
                <groupId>com.alibaba.cloud</groupId>
                <artifactId>spring-cloud-alibaba-dependencies</artifactId>
                <version>${spring.cloud.alibaba.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>

            <!--easy excel-->
            <dependency>
                <groupId>com.alibaba</groupId>
                <artifactId>easyexcel</artifactId>
                <version>${easy.excel.version}</version>
            </dependency>

            <!--mysql-->
            <dependency>
                <groupId>mysql</groupId>
                <artifactId>mysql-connector-java</artifactId>
                <version>${mysql.version}</version>
            </dependency>

            <!--mybatis plus-->
            <dependency>
                <groupId>com.baomidou</groupId>
                <artifactId>mybatis-plus-boot-starter</artifactId>
                <version>${mybatis.plus.version}</version>
            </dependency>

            <!--mybatis plus generator-->
            <dependency>
                <groupId>com.baomidou</groupId>
                <artifactId>mybatis-plus-generator</artifactId>
                <version>${mybatis.plus.version}</version>
            </dependency>

            <!--velocity engine-->
            <dependency>
                <groupId>org.apache.velocity</groupId>
                <artifactId>velocity-engine-core</artifactId>
                <version>${velocity.version}</version>
            </dependency>

            <!--swagger-->
            <dependency>
                <groupId>io.springfox</groupId>
                <artifactId>springfox-swagger2</artifactId>
                <version>${swagger.version}</version>
                <exclusions>
                    <exclusion>
                        <groupId>io.swagger</groupId>
                        <artifactId>swagger-models</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>

            <dependency>
                <groupId>io.swagger</groupId>
                <artifactId>swagger-models</artifactId>
                <version>${swagger.models.version}</version>
            </dependency>

            <dependency>
                <groupId>com.ivan</groupId>
                <artifactId>pinellia-common</artifactId>
                <scope>compile</scope>
                <version>${common.version}</version>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <scope>provided</scope>
        </dependency>

       <!--hutool all-->
        <dependency>
            <groupId>cn.hutool</groupId>
            <artifactId>hutool-all</artifactId>
            <version>${hutool.version}</version>
        </dependency>

    </dependencies>
</project>

子pom文件

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>pinellia</artifactId>
        <groupId>com.ivan</groupId>
        <version>1.0.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>pinellia-service</artifactId>
    <packaging>pom</packaging>
    <modules>
        <module>pinellia-user</module>
        <module>pinellia-system</module>
    </modules>

    <dependencies>

        <!--spring web-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <!--nacos discovery-->
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
        </dependency>

        <!--nacos config-->
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
        </dependency>

        <!--spring boot actuator-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
</project>

配置文件配置

# spring 配置
spring:
  application:
    name: user-service

  profiles:
    active: dev

  cloud:
    nacos:
      # 服务配置
      config:
        server-addr: 39.101.193.232:8848
        file-extension: yaml
        group: USER_SERVICE_DEV_GROUP
        namespace: e39d403d-1700-4c07-a9bf-02d9b72fb813
        ext-config[0]:
          data-id: user-service-param.yaml
          group: USER_SERVICE_DEV_GROUP

      # 服务发现
      discovery:
        server-addr: 39.101.193.232:8848
        namespace: e39d403d-1700-4c07-a9bf-02d9b72fb813
        group: DEV_GROUP
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!