Spring Cloud Hoxton

2020-01-06  本文已影响0人  dotff

一. 项目搭建

  1. yml引用maven变量
    在pom.yml中设置环境
<profiles>
        <profile>
            <id>dev</id>
            <activation>
                <activeByDefault>true</activeByDefault><!--默认激活配置-->
            </activation>
            <properties>
                <profile.name>dev</profile.name><!--当前环境-->
                <config.server-addr>127.0.0.1:8848</config.server-addr><!--配置中心地址-->
                <discovery.server-addr>127.0.0.1:8848</discovery.server-addr>
                <config.group>DEV</config.group> <!--配置中心多环境支持的namespace,使用ID默认为空-->
            </properties>
        </profile>
        <profile>
            <id>test</id>
            <properties>
                <profile.name>test</profile.name>
                <config.server-addr>192.168.48.200:8848</config.server-addr>
                <discovery.server-addr>192.168.48.200:8848</discovery.server-addr>
                <config.namespace/>
            </properties>
        </profile>
    </profiles>

在maven中配置替换占位符

<build>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
            </resource>
        </resources>
</build>

在yml中使用变量

spring:
        profiles:
            active: '@profile.name@'  # dev

另外可以设置${}格式也可以使用maven中的变量

<build>
        <finalName>${project.name}</finalName>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
            </resource>
        </resources>
        <pluginManagement>
            <plugins>
            <!-- 通过设置useDefaultDelimiters -->
                <plugin>
                    <artifactId>maven-resources-plugin</artifactId>
                    <configuration>
                        <encoding>utf-8</encoding>
                        <useDefaultDelimiters>true</useDefaultDelimiters>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
        <plugins>
        </plugins>
    </build>
  1. gateway 查看路由信息
    pom中引入依赖
<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

配置文件中暴露端口

management:
    endpoints:
        web:
            exposure:
                include: "*"
    endpoint:
        health:
            show-details: ALWAYS

url : http://localhost:8888/actuator/gateway/routes
类 : GatewayControllerEndpoint

上一篇下一篇

猜你喜欢

热点阅读