这是我的代码段
@Bean
@ServiceActivator(inputChannel = "topicChannel", outputChannel="responseChannel")
public Employee getEmpDetails() throws Exception {
Expression query = new LiteralExpression("{'name' : '*****'}");
MongoDbMessageSource source = new MongoDbMessageSource(mongoDbFactory(), query);
source.setEntityClass(Employee.class);
source.afterPropertiesSet();
List<Employee> resluts =((List<Employee>)source.receive().getPayload());
return resluts.get(0);
}
以下是错误
java.lang.RuntimeException:没有beanfactory 在org.springframework.integration.expression.ExpressionUtils.createStandardEvaluationContext(ExpressionUtils.java:79) 在org.springframework.integration.mongodb.inbound.MongoDbMessageSource.onInit(MongoDbMessageSource.java:176) 在org.springframework.integration.context.IntegrationObjectSupport.afterPropertiesSet(IntegrationObjectSupport.java:150) 在com.gap.si.configuratoin.MongoDBConfiguration.getEmpDetails(MongoDBConfiguration.java:48) 在com.gap.si.configuratoin.MongoDBConfiguration $$ EnhancerBySpringCGLIB $$ 8e22c38.CGLIB $ getEmpDetails $ 3() 在com.gap.si.configuratoin.MongoDBConfiguration $$ EnhancerBySpringCGLIB $$ 8e22c38 $$ FastClassBySpringCGLIB $$ 99782c25.invoke() 在org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) at org.springframework.context.annotation.ConfigurationClassEnhancer $ BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:309) 在com.gap.si.configuratoin.MongoDBConfiguration $$ EnhancerBySpringCGLIB $$ 8e22c38.getEmpDetails() at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 在java.lang.reflect.Method.invoke(Method.java:483) 在org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162) 在org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588) 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1119) 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1014) 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504) 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476) at org.springframework.beans.factory.support.AbstractBeanFactory $ 1.getObject(AbstractBeanFactory.java:303) 在org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) 在org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299) 在org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) at org.springframework.integration.config.annotation.AbstractMethodAnnotationPostProcessor.resolveTargetBeanFromMethodWithBeanAnnotation(AbstractMethodAnnotationPostProcessor.java:362) 在org.springframework.integration.config.annotation.ServiceActivatorAnnotationPostProcessor.createHandler(ServiceActivatorAnnotationPostProcessor.java:54) 在org.springframework.integration.config.annotation.AbstractMethodAnnotationPostProcessor.postProcess(AbstractMethodAnnotationPostProcessor.java:117) 在org.springframework.integration.config.annotation.MessagingAnnotationPostProcessor $ 1.doWith(MessagingAnnotationPostProcessor.java:151) 在org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:495) 在org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:502) 在org.springframework.integration.config.annotation.MessagingAnnotationPostProcessor.postProcessAfterInitialization(MessagingAnnotationPostProcessor.java:131) 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:422) 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1579) 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539) 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476) at org.springframework.beans.factory.support.AbstractBeanFactory $ 1.getObject(AbstractBeanFactory.java:303) 在org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) 在org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299) 在org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:755) 在org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757) 在org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480) at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118) 在org.springframework.boot.SpringApplication.refresh(SpringApplication.java:686) 在org.springframework.boot.SpringApplication.run(SpringApplication.java:320) 在org.springframework.boot.SpringApplication.run(SpringApplication.java:957) 在org.springframework.boot.SpringApplication.run(SpringApplication.java:946) 在com.gap.si.configuratoin.Application.main(Application.java:16)
答案 0 :(得分:0)
您也应该将rmdir
定义为MongoDbMessageSource
,以便框架正确初始化它;调用@Bean
是不够的。
此外,当afterPropertiesSet()
为@ServiceActivator
时,bean类型必须为@Bean
。对于POJO MessageHandler
方法,请使用@ServiceActivator
。