我们如何将Spring应用程序增量迁移到Micronaut? 我正在寻找将Spring Beans迁移到Micronaut。 我尝试在文档之后使用Spring应用程序中的Micronaut bean,但它并没有消耗
import groovy.util.logging.Slf4j
import org.springframework.test.context.ContextConfiguration
import spock.lang.Specification
import javax.inject.Inject
@Slf4j
@ContextConfiguration(classes = [Config])
class ConsumeBeanSpec extends Specification {
@Inject
ConsumerBean consumerBean
def "should be able to do something"(){
expect:
consumerBean.doSomething()
}
}
当前堆栈跟踪错误: ...省略了36个常见帧 引起:org.springframework.beans.factory.NoSuchBeanDefinitionException:没有'example.ExposedBean'类型的限定bean可用:预期至少有1个bean可以作为autowire候选者。依赖注释:{} 在org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound(DefaultListableBeanFactory.java:1509) at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1104) 在org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1065) 在org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:815) 在org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:721) ...省略了54个常见帧
java.lang.IllegalStateException:无法加载ApplicationContext
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:125)
at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:108)
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:246)
at org.spockframework.spring.SpringTestContextManager.prepareTestInstance(SpringTestContextManager.java:49)
at org.spockframework.spring.SpringInterceptor.interceptSetupMethod(SpringInterceptor.java:42)
at org.spockframework.runtime.extension.AbstractMethodInterceptor.intercept(AbstractMethodInterceptor.java:28)
at org.spockframework.runtime.extension.MethodInvocation.proceed(MethodInvocation.java:87)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
引起:org.springframework.beans.factory.UnsatisfiedDependencyException:在文件[C:\ tools \ micronaut.io \ study \ _meumaut-expose-springs-beans \ out \ production>中定义名称为'consumerBean'的bean创建时出错\ classes \ example \ ConsumerBean.class]:通过构造函数参数0表示的不满意的依赖项;嵌套异常是org.springframework.beans.factory.NoSuchBeanDefinitionException:没有类型'example.ExposedBean'的限定bean可用:预期至少有1个bean可以作为autowire候选者。依赖注释:{} 在org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:729) 在org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:192) 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1274) 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1131) 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:541)
答案 0 :(得分:2)
我已向https://github.com/luistrigueiros/micronaut-expose-spring-beans/pull/1发送了PR,以便您的测试通过。
正如https://docs.micronaut.io/1.0.0.M1/api/io/micronaut/spring/beans/MicronautBeanProcessor.html的javadocs一样,MicronautBeanProcessor
仅处理单例bean。
javadoc对此很清楚。我们将在用户指南中对此进行一些补充。