Spring Boot 项目中 application.properties 无法打包进 target 目录,怎么办?

如何解决 spring boot 项目中 application.properties 无法打包进 target 目录的问题?

问题的原因可能是:

  • application.properties 文件未置于正确位置(src/main/resources)
  • 配置文件名称错误(application.yml 或 application.properties)
  • maven 配置不正确(资源过滤未启用)

解决方案:

  1. 确认位置:
    确保 application.properties 文件位于 src/main/resources 目录下。
  2. 检查名称:
    如果使用 yaml 配置文件,则文件名应为 application.yml;如果使用 properties 配置文件,则文件名应为 application.properties。
  3. 启用过滤:
    在 pom.x

    ml 文件中添加以下代码:

    
        
            src/main/resources
            true