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 options
或Program arguments
框中,添加参数:--spring.config.location=file:/path/to/your/application.yml
。
确保替换/path/to/your/application.yml
为你的application.yml
文件的实际路径。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 零经验选手,Compose 一天开发一款小游戏!
· 因为Apifox不支持离线,我果断选择了Apipost!
· 通过 API 将Deepseek响应流式内容输出到前端
2022-10-25 On branch master nothing to commit, working tree clean