springboot工程,在pom.xml文件中,排除了打包application.yml文件后,运行项目报错的问题

1、排除掉application.yml 文件(maven编译是没有问题的)

 

2、但是在idea 中运行项目,会报 

Error creating bean with name 'loginInterceptor': Unsatisfied dependency expressed through field 'jwtUtil'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jwtUtil': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'SECRET_KEY' in value "${SECRET_KEY}"

其实就是找不到application.yml文件

 

解决方法:

在IDEA中配置一个特定的运行/调试配置,在这个配置中指定Spring Boot的配置文件。这样,即使application.yml不在资源目录中,项目也可以在IDE中正常启动

在IDEA中设置Spring Boot的配置文件路径:

  • 打开Run/Debug Configurations对话框。

  • 在你的应用程序配置中,找到Spring Boot标签。

  • VM optionsProgram arguments框中,添加参数:--spring.config.location=file:/path/to/your/application.yml

确保替换/path/to/your/application.yml为你的application.yml文件的实际路径。

 

posted @   信铁寒胜  阅读(220)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 零经验选手,Compose 一天开发一款小游戏!
· 因为Apifox不支持离线,我果断选择了Apipost!
· 通过 API 将Deepseek响应流式内容输出到前端
历史上的今天:
2022-10-25 On branch master nothing to commit, working tree clean
点击右上角即可分享
微信分享提示