zoukankan      html  css  js  c++  java
  • 配置中包含maven属性,在idea中本地启动无法正常获取配置

    1. 本地启动一个spring cloud 项目,无法启动 (注:测试环境正常),且控台无错误日志。 

    分析:debug 代码发现是配置无法获取。 查看配置获取方式 是 spring config 通过 

    spring:
        application:
            name: cc@project.name.suffix@
        profiles:
            active: '@profile.name@'
    ---
    spring:
        profiles: dev
        cloud:
            config:
                label: dev
                discovery:
                    enabled: true
                    service-id: xx-config
                profile: ${spring.profiles.active}
                fail-fast: true

    先查看xx-config 服务正常。 说明是项目中无法正确读取配置。

    查看上述配置: 如何判断上述配置被程序正常解析了呢?

    按住ctrl ,点击 label 进入 

     发现 profiles 是 @profile.name@ , 这个是maven 的配置属性。 

    这个属性是通过 profile =  dev  的 profile 属性。所以在打包的时候  使用 -P dev 打包即可,或者

    但是打包启动 ,仍然无法启动。 

    查看target 下的 打包文件,发现仍然没有正确读取配置。 难道打包出现了问题。

    再次maven 打包发现文件正常。 点击启动后,发现偶发文件发生变化,配置属性没有被解析。 

    百度了一下发现: idea  spring boot 默认build , 而这个build 就是普通编译。 去掉即可。

  • 相关阅读:
    leetcode319
    leetcode516
    leetcode46
    leetcode337
    leetcode287
    leetcode328
    leetcode241
    2018-6-30-dotnet-设计规范-·-抽象类
    2018-6-30-dotnet-设计规范-·-抽象类
    2018-8-10-WPF-如何画出1像素的线
  • 原文地址:https://www.cnblogs.com/zhangchenglzhao/p/15007155.html
Copyright © 2011-2022 走看看