VS Code打开使用IDEA搭建的Spring Boot项目运行提示"snakeyaml was not found on the classpath"错误
今天用VS Code打开之前基于IDEA搭建并开发的Spring Boot项目,启动调试后出现如下错误:
17:43:05.214 [restartedMain] ERROR org.springframework.boot.SpringApplication - Application run failed java.lang.IllegalStateException: Failed to load property source from location 'classpath:/application.yml' at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.load(ConfigFileApplicationListener.java:538) at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.loadForFileExtension(ConfigFileApplicationListener.java:497) at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.load(ConfigFileApplicationListener.java:465) at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.lambda$null$6(ConfigFileApplicationListener.java:447) at java.lang.Iterable.forEach(Iterable.java:75) at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.lambda$load$7(ConfigFileApplicationListener.java:446) at java.lang.Iterable.forEach(Iterable.java:75) at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.load(ConfigFileApplicationListener.java:443) at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.load(ConfigFileApplicationListener.java:335) at org.springframework.boot.context.config.ConfigFileApplicationListener.addPropertySources(ConfigFileApplicationListener.java:214) at org.springframework.boot.context.config.ConfigFileApplicationListener.postProcessEnvironment(ConfigFileApplicationListener.java:197) at org.springframework.boot.context.config.ConfigFileApplicationListener.onApplicationEnvironmentPreparedEvent(ConfigFileApplicationListener.java:184) at org.springframework.boot.context.config.ConfigFileApplicationListener.onApplicationEvent(ConfigFileApplicationListener.java:170) at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172) at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165) at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139) at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127) at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:74) at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:54) at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:358) at org.springframework.boot.SpringApplication.run(SpringApplication.java:317) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1255) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1243) at com.beyondbit.uffice.resource.ResourceApplication.main(ResourceApplication.java:13) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) Caused by: java.lang.IllegalStateException: Attempted to load applicationConfig: [classpath:/application.yml] but snakeyaml was not found on the classpath at org.springframework.boot.env.YamlPropertySourceLoader.load(YamlPropertySourceLoader.java:47) at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.loadDocuments(ConfigFileApplicationListener.java:556) at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.load(ConfigFileApplicationListener.java:518) ... 28 common frames omitted
启动时找到了application.yml文件,但没有找到snakeyaml的jar。最终错误代码来自于YamlPropertySourceLoader的load方法:
@Override
public List<PropertySource<?>> load(String name, Resource resource)
throws IOException {
if (!ClassUtils.isPresent("org.yaml.snakeyaml.Yaml", null)) {
throw new IllegalStateException("Attempted to load " + name
+ " but snakeyaml was not found on the classpath");
}
List<Map<String, Object>> loaded = new OriginTrackedYamlLoader(resource).load();
if (loaded.isEmpty()) {
return Collections.emptyList();
}
List<PropertySource<?>> propertySources = new ArrayList<>(loaded.size());
for (int i = 0; i < loaded.size(); i++) {
propertySources.add(new OriginTrackedMapPropertySource(
name + (loaded.size() != 1 ? " (document #" + i + ")" : ""),
loaded.get(i)));
}
return propertySources;
}
在IDEA查看项目依赖时候发现snakeyaml是运行时加载的,VS Code不会读取IDEA的iml文件,所以引发了这个问题。
于是打开pom.xml,手动添加对snakeyaml的依赖:
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
</dependency>
VS Code打开使用IDEA搭建的Spring Boot项目运行提示"snakeyaml was not found on the classpath"错误的更多相关文章
- 从零开始的Spring Boot(1、搭建一个Spring Boot项目Hello World)
搭建一个Spring Boot项目Hello World 写在前面 从零开始的Spring Boot(2.在Spring Boot中整合Servlet.Filter.Listener的方式):http ...
- 将Spring Boot项目运行在Docker上
将Spring Boot项目运行在Docker上 一.使用Dockerfile构建Docker镜像 1.1Dockerfile常用指令 1.1.1ADD复制文件 1.1.2ARG设置构建参数 1.1. ...
- 如何搭建一个spring boot项目
什么是springboot? Spring Boot俗称微服务.Spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化新Spring应用的初始搭建以及开发过程.该框架使用了特 ...
- PM2 监控 Spring Boot 项目运行
更多 PM2 的用法介绍请参考: PM2简易使用手册 - 掘金 由于 PM2 通常都用于 node 应用, 所以 exec_mode 应写为 fork, 其中最重要的是 args, -jar 和 ja ...
- 创建spring boot项目并添加多个模块时,启动报 错误: 找不到或无法加载主类
最近建个项目发现启动报,找不到或无法加载主类,想想肯定是自己配置出问题了,经过排查确实出问题了,(根pom中的bulid为移到子模块中去导致的),下面演示下正确的创建子模块的步奏 1. 创 ...
- spring boot项目遇到 'lower_case_table_names' 的解决办法
今天自己搭建了spring boot项目,配置的是mysql数据库,启动时报如下错误 Mon Jan 22 23:31:40 CST 2018 WARN: Establishing SSL conne ...
- Eclipse创建第一个Spring Boot项目
一.安装SpringBoot插件 安装过程需要联网下载插件,属于在线安装,请耐心等待安装完成,下载安装完成以后,需要重启Eclipse 二.创建Spring Boot项目 如下图所示new-other ...
- Spring Boot入门(一):搭建Spring Boot项目
从本篇博客开始,我们开始进入Spring Boot的世界,它的出现使Spring的开发变得更加简洁,因此一经推出受到众多程序员的喜爱. 作为Spring Boot系列的第一篇博客,我们先来讲解下如何搭 ...
- Spring boot入门(一):快速搭建Spring boot项目
(一)Spring boot介绍 本部分摘自:https://www.zhihu.com/question/64671972/answer/223383505 Spring Boot是由Pivotal ...
随机推荐
- js中字符串的方法
js String对象中常用方法小结,需要的朋友可以参考下: 1.charCodeAt方法返回一个整数,代表指定位置字符的Unicode编码. strObj.charCodeAt(index) 说明: ...
- GMA Round 1 最大值
传送门 最大值 求$f(x)=cos(x)+\sqrt{cos^2(x)-4\sqrt{3}cos(x)+4\sqrt{2}sin(x)+10}$的最大值.保留到小数点后3位. $f(x)+\sqrt ...
- 咏南新BS开发框架
咏南新BS开发框架 咏南WEB框架支持负载均衡群集. 咏南WEB桌面框架演示:47.106.93.126:9999 咏南WEB手机框架本地:47.106.93.126:8077 咏南CS框架下载:ht ...
- 在Mac平台上安装配置ELK时的一些总结
一.前言 大数据处理是流行的一些表现,在不断壮大的数据处理中,怎么样处理数据才是我们继续做好开发的正道.本文章来自网络,不敢原创,但是也有很大借鉴. 二.MAC安装ELK 首先是安装elast ...
- SpringMVC的拦截器(Interceptor)和过滤器(Filter)的区别与联系
摘自: http://blog.csdn.net/xiaoyaotan_111/article/details/53817918 一 简介 (1)过滤器: 依赖于servlet容器.在实现上基于函数回 ...
- shell编程学习笔记(三):Shell中局部变量的使用
现在我们看一下Shell中局部变量的使用 以下蓝色字体部分为Linux命令,红色字体的内容为输出的内容: # cd /opt/scripts # vim script03.sh 开始编写script0 ...
- t-SNE 层次聚类
https://zhuanlan.zhihu.com/p/28967965 https://haojunsui.github.io/2016/07/16/scipy-hac/
- TF的模型文件
TF的模型文件 标签(空格分隔): TensorFlow Saver tensorflow模型保存函数为: tf.train.Saver() 当然,除了上面最简单的保存方式,也可以指定保存的步数,多长 ...
- re.S、 re.M
re.S是代表.可以匹配\n以及“ re.M是多行 code import re a = '''asdfsafhellopass: 234455 worldafdsf ''' b = re.fi ...
- [Java并发编程(二)] 线程池 FixedThreadPool、CachedThreadPool、ForkJoinPool?为后台任务选择合适的 Java executors
[Java并发编程(二)] 线程池 FixedThreadPool.CachedThreadPool.ForkJoinPool?为后台任务选择合适的 Java executors ... 摘要 Jav ...