0

我正在尝试使用 JDK 11 和 Micronaut 1.0.2 运行此https://github.com/alvarosanchez/micronaut-workshop micronaut 研讨会示例

更新了一些依赖,它的编译很好。当我运行它的抛出错误时。

21:27:18.607 [main] ERROR io.micronaut.runtime.Micronaut - Error starting Micronaut server: Failed to inject value for parameter [objectMapper] of class: io.micronaut
.jackson.convert.ArrayNodeToArrayConverter

Path Taken: new ArrayNodeToArrayConverter([ObjectMapper objectMapper])
io.micronaut.context.exceptions.DependencyInjectionException: Failed to inject value for parameter [objectMapper] of class: io.micronaut.jackson.convert.ArrayNodeToAr
rayConverter

Path Taken: new ArrayNodeToArrayConverter([ObjectMapper objectMapper])
        at io.micronaut.context.AbstractBeanDefinition.getBeanForConstructorArgument(AbstractBeanDefinition.java:981)
        at io.micronaut.jackson.convert.$ArrayNodeToArrayConverterDefinition.build(Unknown Source)
        at io.micronaut.context.DefaultBeanContext.doCreateBean(DefaultBeanContext.java:1329)
        at io.micronaut.context.DefaultBeanContext.addCandidateToList(DefaultBeanContext.java:2237)
        at io.micronaut.context.DefaultBeanContext.getBeansOfTypeInternal(DefaultBeanContext.java:2165)
        at io.micronaut.context.DefaultBeanContext.getBeansOfType(DefaultBeanContext.java:752)
        at io.micronaut.context.DefaultBeanContext.getBeansOfType(DefaultBeanContext.java:522)
        at io.micronaut.context.DefaultBeanContext.getBeanRegistrations(DefaultBeanContext.java:313)
        at io.micronaut.context.DefaultApplicationContext.initializeTypeConverters(DefaultApplicationContext.java:339)
        at io.micronaut.context.DefaultApplicationContext.initializeContext(DefaultApplicationContext.java:193)
        at io.micronaut.context.DefaultBeanContext.readAllBeanDefinitionClasses(DefaultBeanContext.java:2033)
        at io.micronaut.context.DefaultBeanContext.start(DefaultBeanContext.java:156)
        at io.micronaut.context.DefaultApplicationContext.start(DefaultApplicationContext.java:141)
        at io.micronaut.runtime.Micronaut.start(Micronaut.java:67)
        at io.micronaut.runtime.Micronaut.run(Micronaut.java:271)
        at io.micronaut.runtime.Micronaut.run(Micronaut.java:257)
        at io.micronaut.runtime.Micronaut$run.call(Unknown Source)
        at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:115)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:135)
        at clubs.Application.main(Application.groovy:8)
Caused by: io.micronaut.context.exceptions.BeanInstantiationException: Error instantiating bean of type  [io.micronaut.jackson.convert.ArrayNodeToArrayConverter]

Message: Multiple possible bean candidates found: [io.micronaut.jackson.ObjectMapperFactory, io.micronaut.jackson.ObjectMapperFactory]
Path Taken: new ArrayNodeToArrayConverter([ObjectMapper objectMapper])
        at io.micronaut.context.DefaultBeanContext.doCreateBean(DefaultBeanContext.java:1343)

我的代码在这里https://github.com/sfgroups/micronaut-codes/tree/master/micronaut-workshop-ex02

如何修复此运行时错误?

谢谢

4

1 回答 1

0

根据https://github.com/sfgroups/micronaut-codes/blob/9013a3daeb544cbc040f42091c2ff7995385b6a4/micronaut-workshop-ex02/build.gradle#L29上的配置,您的项目正在使用 Micronaut 1.0.2。

mavenBom 'io.micronaut:micronaut-bom:1.0.2'

https://github.com/sfgroups/micronaut-codes/blob/9013a3daeb544cbc040f42091c2ff7995385b6a4/micronaut-workshop-ex02/build.gradle#L56中,您正在提取与 Micronaut 1.0.2 不兼容的1.0.0.RC2版本。discovery-client

compile group: 'io.micronaut', name: 'discovery-client', version: '1.0.0.RC2'

您将希望将该版本更新到 1.0.2 并希望引用micronaut-discovery-client而不是discovery-client(RC2 后模块名称更改)。最简单的表达方式是这样的:

compile 'io.micronaut:micronaut-discovery-client'

解决此问题后,您将看到项目中存在其他问题,但上述解决了问题中描述的问题。

我希望这会有所帮助。

于 2018-12-27T20:02:30.703 回答