• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

Spring Boot基础解决ERROR org.springframework.boot.SpringApplication -- Application run failed报错问题

武飞扬头像
林月明
帮助11

一、问题描述

在学习SpringBoot配置profile的时候,.yml文件内容明明跟老师敲的一模一样,但还是报错ERROR org.springframework.boot.SpringApplication -- Application run failed

原.yml文件内容:

  1.  
    ---
  2.  
    server :
  3.  
    port : 8081
  4.  
     
  5.  
    spring:
  6.  
    profiles: dev
  7.  
     
  8.  
    ---
  9.  
    server :
  10.  
    port : 8082
  11.  
     
  12.  
    spring:
  13.  
    profiles: test
  14.  
     
  15.  
    ---
  16.  
    server :
  17.  
    port : 8083
  18.  
     
  19.  
    spring:
  20.  
    profiles: pro
  21.  
     
  22.  
    ---
  23.  
     
  24.  
    spring:
  25.  
    profiles:
  26.  
    active: pro
学新通

报错如下:

学新通

 二、解决方法

按照“ERROR org.springframework.boot.SpringApplication -- Application run failed”搜索答案,试了好久都没能解决,还是回过头来一句句分析自己的报错情况吧!

发现报错中提示“ Property 'spring.profiles' imported from location 'class path resource [application.yml]' is invalid and should be replaced with 'spring.config.activate.on-profile'...”,感悟到一点意思了,spring.profiles应该被spring.config.activate.on-profile代替。

"spring.profiles"我在yml文件里写过,怀疑是不是要改为spring.config.activate.on-profile的意思。将原句删除后,当输入s时提示框里便出现了“spring.config.activate.on-profile”,果不其然。

学新通

 得出两点体悟:

1、不要死读书不变通,老师讲的内容照抄照搬过来不一定在自己的环境版本下运行顺利;

2、遇事应沉着冷静,不要胡乱发力,找准痛点,扎扎实实去分析解决。

三、修改之后的.yml文件内容

  1.  
    ---
  2.  
    server :
  3.  
    port : 8081
  4.  
     
  5.  
    spring:
  6.  
    config:
  7.  
    activate:
  8.  
    on-profile: dev
  9.  
     
  10.  
    ---
  11.  
    server :
  12.  
    port : 8082
  13.  
     
  14.  
    spring:
  15.  
    config:
  16.  
    activate:
  17.  
    on-profile: test
  18.  
     
  19.  
    ---
  20.  
    server :
  21.  
    port : 8083
  22.  
     
  23.  
    spring:
  24.  
    config:
  25.  
    activate:
  26.  
    on-profile: pro
  27.  
     
  28.  
    ---
  29.  
     
  30.  
    spring:
  31.  
    profiles:
  32.  
    active: pro
学新通

四、控制台运行结果

学新通

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhcijahj
系列文章
更多 icon
同类精品
更多 icon
继续加载