0

我正在使用带有 Spring-context 5.0.0.RELEASE 的 Kotlin 1.1.4-3。

在启动项目时,我收到此错误:

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'coroutineAnnotationBeanPostProcessor' defined in class path resource [org/springframework/kotlin/experimental/coroutine/context/ProxyCoroutineConfiguration.class]: Unsatisfied dependency expressed through method 'coroutineAnnotationBeanPostProcessor' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'globalCoroutineContextResolver' defined in class path resource [org/springframework/kotlin/experimental/coroutine/context/CoroutineContextResolverConfiguration.class]: Unexpected exception during bean creation; nested exception is java.lang.reflect.InvocationTargetException
        at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:723)
        at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:458)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1249)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1098)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:502)
        at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:312)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:310)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:205)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'globalCoroutineContextResolver' defined in class path resource [org/springframework/kotlin/experimental/coroutine/context/CoroutineContextResolverConfiguration.class]: Unexpected exception during bean creation; nested exception is java.lang.reflect.InvocationTargetException
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:518)
        at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:312)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:310)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200)
        at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:251)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1133)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1060)
        at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:809)
        at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:715)
Caused by: java.lang.reflect.InvocationTargetException: null
        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 kotlin.reflect.jvm.internal.impl.load.kotlin.reflect.ReflectClassStructure.processAnnotationArguments(ReflectKotlinClass.kt:173)
        at kotlin.reflect.jvm.internal.impl.load.kotlin.reflect.ReflectClassStructure.processAnnotation(ReflectKotlinClass.kt:162)
        at kotlin.reflect.jvm.internal.impl.load.kotlin.reflect.ReflectClassStructure.loadMethodAnnotations(ReflectKotlinClass.kt:97)
        at kotlin.reflect.jvm.internal.impl.load.kotlin.reflect.ReflectClassStructure.visitMembers(ReflectKotlinClass.kt:87)
        at kotlin.reflect.jvm.internal.impl.load.kotlin.reflect.ReflectKotlinClass.visitMembers(ReflectKotlinClass.kt:68)
        at kotlin.reflect.jvm.internal.impl.load.kotlin.AbstractBinaryClassAnnotationAndConstantLoader.loadAnnotationsAndInitializers(AbstractBinaryClassAnnotationAndConstantLoader.kt:257)
Caused by: java.lang.TypeNotPresentException: Type rx.Scheduler not present
        at sun.reflect.annotation.TypeNotPresentExceptionProxy.generateException(TypeNotPresentExceptionProxy.java:46)
        at sun.reflect.annotation.AnnotationInvocationHandler.invoke(AnnotationInvocationHandler.java:84)
        at com.sun.proxy.$Proxy166.value(Unknown Source)
        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 kotlin.reflect.jvm.internal.impl.load.kotlin.reflect.ReflectClassStructure.processAnnotationArguments(ReflectKotlinClass.kt:173)
        at kotlin.reflect.jvm.internal.impl.load.kotlin.reflect.ReflectClassStructure.processAnnotation(ReflectKotlinClass.kt:162)
        at kotlin.reflect.jvm.internal.impl.load.kotlin.reflect.ReflectClassStructure.loadMethodAnnotations(ReflectKotlinClass.kt:97)
Caused by: java.lang.ClassNotFoundException: rx.Scheduler
        at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:348)
        at sun.reflect.generics.factory.CoreReflectionFactory.makeNamedType(CoreReflectionFactory.java:114)
        at sun.reflect.generics.visitor.Reifier.visitClassTypeSignature(Reifier.java:125)
        at sun.reflect.generics.tree.ClassTypeSignature.accept(ClassTypeSignature.java:49)
        at sun.reflect.annotation.AnnotationParser.parseSig(AnnotationParser.java:439)
        at sun.reflect.annotation.AnnotationParser.parseClassValue(AnnotationParser.java:420)

似乎 spring 正在寻找rx.Scheduler类,但它不在类路径中。很明显rx.Scheduler没有添加相应的依赖。但我在互联网上找不到任何相关的东西。

我将 RxJava2 ( io.reactivex.rxjava2) 添加到项目中,但它不起作用。我能做些什么?

最终答案 - 基于 Rafal G. 回复:

这个错误是因为使用了 konrad-kaminski/spring-kotlin-coroutine库。但是,我在我的项目中使用了这些依赖项:

  "org.springframework.kotlin" % "spring-kotlin-coroutine" % "0.2.2" exclude("org.jetbrains.kotlinx", "kotlinx-coroutines"),

  "org.springframework" % "spring-context" % "5.0.0.RELEASE",
  "org.springframework.data" % "spring-data-jpa" % "2.0.0.RELEASE",

  // https://mvnrepository.com/artifact/io.reactivex.rxjava2/rxjava
  "io.reactivex.rxjava2" % "rxjava" % "2.1.4",

  // https://mvnrepository.com/artifact/io.reactivex/rxjava
  "io.reactivex" % "rxjava" % "1.3.2",

  // https://mvnrepository.com/artifact/io.projectreactor/reactor-core
  "io.projectreactor" % "reactor-core" % "3.1.0.RELEASE"
4

1 回答 1

2

您需要使用 RxJava 1,因为它是定义类 rx.Schedulers 的地方。

于 2017-10-03T14:37:50.557 回答