NoSuchMethodError: org.yaml.snakeyaml.Yaml

Spring Boot Project Error in Eclipse TestNG:

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/resolver/Resolver;)V

 


15:59:52.645 [main] ERROR org.springframework.test.context.TestContextManager - Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@69b794e2] to prepare test instance [com.xxx.rds.frtool.service.RdsReportsServiceTests@4c40b76e]
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/resolver/Resolver;)V
	at org.springframework.boot.env.YamlPropertySourceLoader$Processor.createYaml(YamlPropertySourceLoader.java:86)
	at org.springframework.beans.factory.config.YamlProcessor.process(YamlProcessor.java:136)
	at org.springframework.boot.env.YamlPropertySourceLoader$Processor.process(YamlPropertySourceLoader.java:101)
	at org.springframework.boot.env.YamlPropertySourceLoader.load(YamlPropertySourceLoader.java:58)
	at com.xxx.base.service.util.YamlApplicationContextInitializer.initialize(YamlApplicationContextInitializer.java:27)
	at org.springframework.test.context.support.AbstractContextLoader.invokeApplicationContextInitializers(AbstractContextLoader.java:170)
	at org.springframework.test.context.support.AbstractContextLoader.prepareContext(AbstractContextLoader.java:138)
	at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:122)
	at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:60)
	at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:108)
	at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:251)
	at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:98)
	at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:116)
	at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:83)
	at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:117)
	at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:83)
	at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:230)
	at org.springframework.test.context.testng.AbstractTestNGSpringContextTests.springTestContextPrepareTestInstance(AbstractTestNGSpringContextTests.java:149)
	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.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
	at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:564)
	at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:213)
	at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:138)
	at org.testng.internal.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:175)
	at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:107)
	at org.testng.TestRunner.privateRun(TestRunner.java:767)
	at org.testng.TestRunner.run(TestRunner.java:617)
	at org.testng.SuiteRunner.runTest(SuiteRunner.java:335)
	at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:330)
	at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
	at org.testng.SuiteRunner.run(SuiteRunner.java:240)
	at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
	at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
	at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
	at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
	at org.testng.TestNG.run(TestNG.java:1057)
	at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
	at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
	at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)
15:59:52.660 [main] DEBUG org.springframework.test.context.support.AbstractDirtiesContextTestExecutionListener - After test method: context [DefaultTestContext@1460a8c0 testClass = RdsReportsServiceTests, testInstance = com.xxx.rds.frtool.service.RdsReportsServiceTests@4c40b76e, testMethod = testFindReport@RdsReportsServiceTests, testException = [null], mergedContextConfiguration = [MergedContextConfiguration@4f638935 testClass = RdsReportsServiceTests, locations = '{}', classes = '{class com.xxx.rds.frtool.service.BaseTest$TestConfiguration}', contextInitializerClasses = '[class com.xxx.base.service.util.YamlApplicationContextInitializer]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{}', contextCustomizers = set[org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@77a57272, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@6e2c9341, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@0, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizerFactory$Customizer@10b48321], contextLoader = 'org.springframework.test.context.support.DelegatingSmartContextLoader', parent = [null]]], class annotated with @DirtiesContext [false] with mode [null], method annotated with @DirtiesContext [false] with mode [null].
15:59:52.661 [main] DEBUG org.springframework.test.context.support.AbstractDirtiesContextTestExecutionListener - After test class: context [DefaultTestContext@1460a8c0 testClass = RdsReportsServiceTests, testInstance = [null], testMethod = [null], testException = [null], mergedContextConfiguration = [MergedContextConfiguration@4f638935 testClass = RdsReportsServiceTests, locations = '{}', classes = '{class com.xxx.rds.frtool.service.BaseTest$TestConfiguration}', contextInitializerClasses = '[class com.xxx.base.service.util.YamlApplicationContextInitializer]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{}', contextCustomizers = set[org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@77a57272, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@6e2c9341, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@0, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizerFactory$Customizer@10b48321], contextLoader = 'org.springframework.test.context.support.DelegatingSmartContextLoader', parent = [null]]], class annotated with @DirtiesContext [false] with mode [null].
FAILED CONFIGURATION: @BeforeClass springTestContextPrepareTestInstance
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/resolver/Resolver;)V
	at org.springframework.boot.env.YamlPropertySourceLoader$Processor.createYaml(YamlPropertySourceLoader.java:86)
	at org.springframework.beans.factory.config.YamlProcessor.process(YamlProcessor.java:136)
	at org.springframework.boot.env.YamlPropertySourceLoader$Processor.process(YamlPropertySourceLoader.java:101)
	at org.springframework.boot.env.YamlPropertySourceLoader.load(YamlPropertySourceLoader.java:58)
	at com.xxx.base.service.util.YamlApplicationContextInitializer.initialize(YamlApplicationContextInitializer.java:27)
	at org.springframework.test.context.support.AbstractContextLoader.invokeApplicationContextInitializers(AbstractContextLoader.java:170)
	at org.springframework.test.context.support.AbstractContextLoader.prepareContext(AbstractContextLoader.java:138)
	at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:122)
	at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:60)
	at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:108)
	at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:251)
	at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:98)
	at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:116)
	at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:83)
	at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:117)
	at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:83)
	at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:230)
	at org.springframework.test.context.testng.AbstractTestNGSpringContextTests.springTestContextPrepareTestInstance(AbstractTestNGSpringContextTests.java:149)
	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.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
	at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:564)
	at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:213)
	at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:138)
	at org.testng.internal.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:175)
	at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:107)
	at org.testng.TestRunner.privateRun(TestRunner.java:767)
	at org.testng.TestRunner.run(TestRunner.java:617)
	at org.testng.SuiteRunner.runTest(SuiteRunner.java:335)
	at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:330)
	at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
	at org.testng.SuiteRunner.run(SuiteRunner.java:240)
	at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
	at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
	at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
	at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
	at org.testng.TestNG.run(TestNG.java:1057)
	at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
	at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
	at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)

SKIPPED CONFIGURATION: @BeforeMethod springTestContextBeforeTestMethod
SKIPPED: testFindReport

===============================================
    Default test
    Tests run: 1, Failures: 0, Skips: 1
    Configuration Failures: 1, Skips: 1
===============================================


===============================================
Default suite
Total tests run: 1, Failures: 0, Skips: 1
Configuration Failures: 1, Skips: 1
===============================================

[TestNG] Time taken by org.testng.reporters.SuiteHTMLReporter@96532d6: 71 ms
[TestNG] Time taken by org.testng.reporters.jq.Main@6442b0a6: 20 ms
[TestNG] Time taken by org.testng.reporters.XMLReporter@3498ed: 5 ms
[TestNG] Time taken by [FailedReporter passed=0 failed=0 skipped=0]: 9 ms
[TestNG] Time taken by org.testng.reporters.JUnitReportReporter@6b2fad11: 6 ms
[TestNG] Time taken by org.testng.reporters.EmailableReporter2@3cda1055: 5 ms

1, 在网上查了一下,说是yaml包冲突,于是试了以下配置,但没有解决,即使是升级了testng版本。

		<dependency>
		    <groupId>org.testng</groupId>
		    <artifactId>testng</artifactId>
		    <version>6.8.21</version>
		    <scope>test</scope>
	      	<exclusions>
	          <exclusion>
	              <artifactId>snakeyaml</artifactId>
	              <groupId>org.yaml</groupId>
	          </exclusion>
	       </exclusions>
		</dependency>

2,查看了Meven的依赖情况,也没有发现问题。

05f0bebccded4a40a17f99f4bda7aa9f7b8.jpg

 

3, 试着升级了yaml包的版本,但还是没有效果。

<dependency>
			<artifactId>snakeyaml</artifactId>
            <groupId>org.yaml</groupId>
            <version>1.18</version>
            <scope>test</scope>
		</dependency>

4, 正在对问题感到奇怪的时候,突然想到了Eclipse TestNG插件。因为可以肯定是环境的问题。

原来的TestNG插件版本是testng6.8.6。现在更新到6.14版本,重新启动Eclipse和运行测试用例,问题消失!!!

 

转载于:https://my.oschina.net/jerval/blog/1833607

### 回答1: 这是一个Java程序的错误信息,意思是找不到方法org.yaml.snakeyaml.LoaderOptions.setMaxAliasesForCollections(int),导致程序无法运行。可能是因为程序中调用了这个方法,但是这个方法不存在或者版本不匹配。需要检查程序中是否正确引入了相关的库文件,并且检查代码中是否正确使用了这个方法。 ### 回答2: 这个错误是由于在程序运行中找不到特定方法所导致的。具体来说,这个错误是指程序在使用 SnakeYAML 库时出现了问题,这可能是因为程序使用的 SnakeYAML 版本与它所期望的版本不匹配。 具体地说,错误消息 "java.lang.nosuchmethoderror: org.yaml.snakeyaml.loaderoptions.setmaxaliasesforcollections(i)v" 意味着程序无法找到在 SnakeYAML 库中定义的 setmaxaliasesforcollections 方法。它的参数表明它应该接受一个整数参数,但在程序中它被调用时参数类型有误,或者是该方法在当前版本的 SnakeYAML 库中已被删除或重命名。 为了解决此问题,您可以尝试升级您的程序依赖项中的 SnakeYAML 库版本,或了解在此版本中是否有这种方法的替代方法。如果您不确定哪个版本的 SnakeYAML 库与您的程序兼容,请查阅SnakeYAML 文档或者联系SnakeYAML社区进行帮助。 ### 回答3: 这个错误是Java运行时环境中出现的一种运行时异常。也就是说,当你运行一个使用了 yaml 库的程序时,程序会报错。 具体地说,当某个类调用 yaml 库中的方法时,如果该方法不存在,就会抛出该异常。这个异常通常是因为使用的 yaml 版本不兼容、方法名书写错误、方法参数不正确等问题导致的。 解决这个问题的方法一般有以下几种: 1. 升级 yaml 版本。你可以在 Maven 或 Gradle 等项目管理工具中修改 yaml 的依赖版本,让它与你的项目兼容。 2. 检查代码书写。你需要检查你的代码是否正确地引用了相应的库,同时也要检查方法名、参数等是否正确。 3. 确认程序是否正确配置。有时候,某些类或 jar 包并没有被正确地部署到你的程序中,导致该异常的出现。你需要确认程序正确部署和配置。 总结来说,当出现这个异常时,你需要注意你所使用的 yaml 版本和代码书写是否正确,并确认程序是否正确部署和配置。只要哪个环节有误,就有可能导致出现该异常,并且需要仔细检查才能解决。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值