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 @ 2024-10-25 09:34  信铁寒胜  阅读(355)  评论(0)    收藏  举报