9

SnakeYaml jar present at classPath: snakeyaml-1.26.jar

2330 [main] ERROR org.springframework.boot.SpringApplication  - Application run failed
java.lang.NoSuchMethodError: org.yaml.snakeyaml.Yaml.<init>(Lorg/yaml/snakeyaml/constructor/BaseConstructor;Lorg/yaml/snakeyaml/representer/Representer;Lorg/yaml/snakeyaml/DumperOptions;Lorg/yaml/snakeyaml/LoaderOptions;Lorg/yaml/snakeyaml/resolver/Resolver;)V
    at org.springframework.boot.env.OriginTrackedYamlLoader.createYaml(OriginTrackedYamlLoader.java:71)
    at org.springframework.beans.factory.config.YamlProcessor.process(YamlProcessor.java:162)
    at org.springframework.boot.env.OriginTrackedYamlLoader.load(OriginTrackedYamlLoader.java:76)
    at org.springframework.boot.env.YamlPropertySourceLoader.load(YamlPropertySourceLoader.java:50)
    at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.loadDocuments(ConfigFileApplicationListener.java:607)
Andy Wilkinson
  • 108,729
  • 24
  • 257
  • 242
IAmHere
  • 113
  • 1
  • 1
  • 5

5 Answers5

5

I had a similar problem and my solution was to use snakeyaml in the exact same version as spring boot does.

In general a good trick is to import maven dependencies from org.springframework.boot:spring-boot-dependencies in order to avoid version incompatibilities.

If you're using mvn, add this under <dependencyManagement> in your pom:

      <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-dependencies</artifactId>
        <version>${spring.boot.version}</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>

and then this under <dependencies>:

    <dependency>
      <groupId>org.yaml</groupId>
      <artifactId>snakeyaml</artifactId>
      <scope>runtime</scope>
    </dependency>

For example spring-boot-dependencies-2.3.6.RELEASE.pom uses snakeyaml in 1.26:

 <snakeyaml.version>1.26</snakeyaml.version>

Whereas spring-boot-dependencies-2.5.12.pom uses 1.28:

 <snakeyaml.version>1.28</snakeyaml.version>

And spring-boot-dependencies-2.6.1.pom uses 1.29:

 <snakeyaml.version>1.29</snakeyaml.version>

Hope this helps.

Alexander
  • 2,925
  • 3
  • 33
  • 36
  • This should be marked the answer. In the question, he's obviously importing an outdated version of snakeyml that's not compatible with Spring Boot. I resolved a very similar error complaining about a missing ParseImpl constructor, and it was because I was importing snakeyaml 1.30 but I needed 1.33 – ChicagoCyclist Jan 30 '23 at 17:50
  • I was using Spring Boot 2.7.6. – ChicagoCyclist Jan 30 '23 at 17:56
3

Please upgrade to 2.7.10 if you are using JDK 11 and no plan to upgrade to springboot 3.x having dependency on JDK 17.

Root cause of the issue is mentioned and fixed here

Other solution is to move to application.properties instead of application.yml, so that you will not encounter this issue.

2

I received this error when I updated snakeyaml from 1.33 to 2.0. You need to downgrade version to 1.33

    <dependency>
        <groupId>org.yaml</groupId>
        <artifactId>snakeyaml</artifactId>
        <version>1.33</version>
    </dependency>

link to mvn repo : https://mvnrepository.com/artifact/org.yaml/snakeyaml

Tomasz
  • 884
  • 8
  • 12
  • 7
    Note, there are vulnerabilities with 1.33 (as of today, march 2023 timeline). Upvote for the answer. But it will put you in a catch22 if you do the downgrade. See https://mvnrepository.com/artifact/org.yaml/snakeyaml/1.33 – granadaCoder Mar 22 '23 at 19:48
  • 4
    Are there any known ways of avoiding these vulnerabilities without having to deal with this error? – maun Mar 23 '23 at 07:47
  • Bad solution. you're not thinking about vulnerabilities Spring boot 3.1.2 and snakeyaml 2.1 works fine. – Erick Jhorman Romero Aug 16 '23 at 14:58
2

Upgrading Jackson to 2.15.0 resolved the issue for me.

Davis Benny
  • 99
  • 1
  • 3
0

Keeping jackson at 2.15.2 and snakeyaml at 1.33 resolved issue for me.

hitesh bedre
  • 459
  • 2
  • 11