MonkeyCoder
V2EX  ›  Java

IDEA 搭配 springboot 的 spring profile 问题

  •  
  •   MonkeyCoder · Oct 25, 2021 · 3884 views
    This topic created in 1840 days ago, the information mentioned may be changed or developed.

    新搞了一个工程.配置了多环境.然后 idea 只能够识别到 application.yml 和 application-prod.yml 这两个文件,application-dev.yml 是无法识别的.网上找了一圈都不行.有大佬知道吗?

    16 replies  •  2021-10-29 17:39:25 +08:00
    imiem
    imiem
    Oct 25, 2021
    1
    idea 无法识别是什么意思?文件在 idea 中看不到?
    MonkeyCoder
    MonkeyCoder
    OP
    Oct 25, 2021
    2
    @imiem #1 就是文件图标不是绿叶.就是普通的文本文件,没有代码高亮和代码提示,但是 application-prod 是没问题的
    longchen888
    longchen888
    Oct 25, 2021
    3
    file -> invalidate caches/restart 试试
    micean
    micean
    Oct 25, 2021
    4
    你先确认 target/classes 里有没有你想要的 yml 文件
    MonkeyCoder
    MonkeyCoder
    OP
    Oct 25, 2021
    5
    @longchen888 #3 第一时间就试了.没用
    MonkeyCoder
    MonkeyCoder
    OP
    Oct 25, 2021
    6
    @micean #4 有的
    mgzu
    mgzu
    Oct 25, 2021
    7
    2021.2.3 ,application-* 文件识别没有问题。idea 有问题,我一般都是以下方法尝试解决
    1. invalidate caches
    2. 删除 .idea 、iml 文件,重新打开项目
    hiwind
    hiwind
    Oct 25, 2021
    8
    这还真没遇到过,应该就是编译缓存的问题 不行的话试试重启?基于 prod 再新建一个试试?
    xiao109
    xiao109
    Oct 25, 2021
    9
    那可能是你文件的后缀有问题,建议删除重建
    wolfie
    wolfie
    Oct 25, 2021
    10
    命令行启动没问题?

    IDEA Edit Configurations ,检查一下 VM options 、Program Arguments 、Active Profiles 都可能设置参数。
    szuwl
    szuwl
    Oct 25, 2021
    11
    建议无视,解决这种问题极其浪费时间
    dzhhh
    dzhhh
    Oct 25, 2021
    12
    Settings -> Editor -> File Types ,找到 Text ,看 File name patterns 有没有匹配到 application-dev.yml 的情况,有就删掉
    MonkeyCoder
    MonkeyCoder
    OP
    Oct 25, 2021
    13
    谢谢大家.楼上说的那些方法我之前都试过.不好使.但还是解决了.分享一下就是把 yml 的文件后缀名改成 yaml 就好了
    zliea
    zliea
    Oct 26, 2021
    14
    偷偷的看下我的,能识别
    GunsRose
    GunsRose
    Oct 29, 2021
    15
    其实你在定义 pom 文件的时候就要指定对应的开发环境, <profiles> <profile>
    <id>sit</id>
    <activation>
    <!--当我们没有显式指定环境时, maven 会默认取 activeByDefault 为 true 的 profile -->
    <activeByDefault>true</activeByDefault>
    </activation>
    <properties>
    <env>sit</env>
    </properties>
    </profile></profiles>
    MonkeyCoder
    MonkeyCoder
    OP
    Oct 29, 2021
    16
    @GunsRose #15 这个肯定配置了.问题已经解决了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   524 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 43ms · UTC 20:10 · PVG 04:10 · LAX 12:10 · JFK 15:10
    ♥ Do have faith in what you're doing.