美文网首页
Spring Cloud Hoxton

Spring Cloud Hoxton

作者: dotff | 来源:发表于2020-01-06 10:34 被阅读0次

    一. 项目搭建

    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

    相关文章

      网友评论

          本文标题:Spring Cloud Hoxton

          本文链接:https://www.haomeiwen.com/subject/dvvhactx.html