java.lang.NoClassDefFoundError:javaslang / collection / LinkedHashMap使用jmh对spring数据应用程序进行基准测试

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java.lang.NoClassDefFoundError:javaslang / collection / LinkedHashMap使用jmh对spring数据应用程序进行基准测试相关的知识,希望对你有一定的参考价值。

我有spring数据JPA应用程序,我想使用jmh对应用程序进行基准测试。

我正在使用gradle构建工具并使用gradle-jmh-plugin

我的github存储库是here

我想基准创建Person实体进行基准测试,基准测试代码是here

每当我使用命令gradle :aerospike-benchmark-demo:jmh --stacktrace运行此基准测试时,我总是得到以下异常。

10:01:40.688 [com.aerospike.benchmark.AerospikeCreateBenchMarkDemo.createPerson-jmh-worker-1] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Retrieved dependent beans for bean 'aerospikeClient': [aerospikeTemplate]
10:01:40.688 [com.aerospike.benchmark.AerospikeCreateBenchMarkDemo.createPerson-jmh-worker-1] DEBUG org.springframework.beans.factory.support.DisposableBeanAdapter - Invoking destroy method 'close' on bean with name 'aerospikeClient'

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'personRepository': Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: javaslang/collection/LinkedHashMap
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1628)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:742)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543)
    at org.springframework.context.annotation.AnnotationConfigApplicationContext.<init>(AnnotationConfigApplicationContext.java:84)
    at com.aerospike.benchmark.AerospikeCreateBenchMarkDemo.createPerson(AerospikeCreateBenchMarkDemo.java:62)
    at com.aerospike.benchmark.generated.AerospikeCreateBenchMarkDemo_createPerson_jmhTest.createPerson_avgt_jmhStub(AerospikeCreateBenchMarkDemo_createPerson_jmhTest.java:402)
    at com.aerospike.benchmark.generated.AerospikeCreateBenchMarkDemo_createPerson_jmhTest.createPerson_AverageTime(AerospikeCreateBenchMarkDemo_createPerson_jmhTest.java:306)
    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.openjdk.jmh.runner.BenchmarkHandler$BenchmarkTask.call(BenchmarkHandler.java:453)
    at org.openjdk.jmh.runner.BenchmarkHandler$BenchmarkTask.call(BenchmarkHandler.java:437)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NoClassDefFoundError: javaslang/collection/LinkedHashMap
    at org.springframework.data.repository.util.JavaslangCollections$FromJavaConverter.<clinit>(JavaslangCollections.java:143)
    at org.springframework.data.repository.util.QueryExecutionConverters.registerConvertersIn(QueryExecutionConverters.java:206)
    at org.springframework.data.repository.core.support.QueryExecutionResultHandler.<init>(QueryExecutionResultHandler.java:44)
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.<init>(RepositoryFactorySupport.java:409)
    at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:221)
    at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.initAndReturn(RepositoryFactoryBeanSupport.java:277)
    at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:263)
    at org.springframework.data.aerospike.repository.support.AerospikeRepositoryFactoryBean.afterPropertiesSet(AerospikeRepositoryFactoryBean.java:63)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1687)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1624)
    ... 25 more
Caused by: java.lang.ClassNotFoundException: javaslang.collection.LinkedHashMap
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 35 more

我不确定如何将AerospikeConfig和PersonRepository自动装配到Benchmarking类。

答案

好像你缺乏javaslang依赖。同

compile group: 'com.javaslang', name: 'javaslang', version: '2.0.0-RC4'

添加到aerospike-demo / build.gradle,它运行并至少显示一些数字。

以上是关于java.lang.NoClassDefFoundError:javaslang / collection / LinkedHashMap使用jmh对spring数据应用程序进行基准测试的主要内容,如果未能解决你的问题,请参考以下文章