2015-09-02 47 views
1

這是我的代碼片段MongodbMessageSource在Spring集成拋出錯誤沒有的beanfactory

@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 at org.springframework.integration.expression.Expressi onUtils.createStandardEvaluationContext(ExpressionUtils.java:79) at org.springframework.integration.mongodb.inbound.MongoDbMessageSource.onInit(MongoDbMessageSource.java:176) at 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() 在融爲一體。 gapi.configuratoin.MongoDBConfiguration $$ EnhancerBySpringCGLIB $$ 8e22c38 $$ FastClassBySpringCGLIB $$ 99782c25.invoke() at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) at org.springframework.context .annotation.ConfigurationClassEn hancer $ BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:309) 在com.gap.si.configuratoin.MongoDBConfiguration $$ EnhancerBySpringCGLIB $$ 8e22c38.getEmpDetails() 在sun.reflect.NativeMethodAccessorImpl.invoke0(本機方法) 在陽光下。 reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 在sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 在java.lang.reflect.Method.invoke(Method.java:483) 在有機springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162) at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588) at 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) 在org.springframework.beans.factory.support.AbstractBeanFactory $ 1.getObject( AbstractBeanFactory.java:303) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) at org.spr在org.springframework.integration.config處的org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) 中提供了以下框架:ingframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299) 。 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) at 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) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539) 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476) 在org.springframework.beans.factory.support.AbstractBeanFactory $ 1.getObject(AbstractBeanFactory.java:303) 在org.springframework .beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299) at org.springframework.beans.factory.support .AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:755) at org.springframework.context.support.AbstractApplicationCont ext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480) at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java: 118) at org.springframework.boot.SpringApplication.run(SpringApplication.java:686) at org.springframework.boot.SpringApplication.run(SpringApplication.java:320) at org.springframework.boot.SpringApplication.run( SpringApplication.java:957) at org.springframework.boot.SpringApplication.run(SpringApplication.java:946) at com.gap.si.configuratoin.Application.main(Application.java:16)

回答

0

您應該將MongoDbMessageSource定義爲@Bean,以便框架正確初始化它;撥打afterPropertiesSet()是不夠的。

另外,當@ServiceActivator@Bean時,bean類型必須是MessageHandler。對於POJO @ServiceActivator方法,請使用@MessageEndoint

+0

感謝加里的回覆..第二點是作爲一個新手有點混亂。請用一些例子來解釋。 –

+0

請閱讀[註釋端點文檔](http://docs.spring.io/spring-integration/reference/html/configuration.html#annotations),如果您有特定問題,請返回。 –

+0

現在我可以從數據庫中獲得結果,方法的錯誤是「找到模糊參數類型[方法匹配類java.lang.Void]」。代碼片段是[link](http://pastebin.com/Fdx16ieG) –