2016-07-27 20 views
1

我收到以下錯誤,當我嘗試使用延遲選項的IntegrationFlowBuilderMongoDbMessageStore無法確定IsNewStrategy錯誤

不支持的實體org.springframework.integration.mongodb.store.MongoDbMessageStore $ MessageWrapper!無法確定IsNewStrategy。

我看的https://jira.spring.io/browse/INT-3346歷史,它似乎是相關的,但這個問題似乎已經固定在我使用的版本(我看到了_id字段)。

當我遍歷代碼時,看起來好像通過我的MongoConfig映射的映射上下文(和IsNewStrategy)被用來代替似乎在MongoDbMessageStore中配置的東西。因此,它有權訪問我的所有域實體(用@Document註釋的那些)的實體信息,但不能訪問MessageWrapper。

我在配置中丟失了什麼嗎?有沒有辦法強制MessageWrapper實體的註冊?

使用
Spring集成 - 4.2.4
春數據蒙戈 - 1.8.2

集成流程

IntegrationFlows.from("channel.in").delay("group1", 
    s -> s.defaultDelay(3000).messageStore(messageStore)) 
    .handle(<somehandler>).get() 

消息存儲配置

@Bean 
public MessageGroupStore messageStore(MongoDbFactory mongoDbFactory) { 
    return new MongoDbMessageStore(mongoDbFactory, "messageStoreCollection") 
} 

蒙戈配置

@Configuration 
@EnableMongoAuditing 
public class MongoConfig extends AbstractMongoConfiguration { 

    @Bean 
    public MongoClient mongo() throws UnknownHostException { 
     MongoClientOptions.Builder builder = new MongoClientOptions.build(); 
     MongoClientOptions options = builder.connectionsPerHost(100).build(); 
     return new MongoClient(new ServerAddress("localhost", 28017)), options); 
    } 

    protected String getDatabaseName() { return "myMongoDb"; } 

    protected String getMappingBasePackage() { return "com.mycompany.myapp.entities"; } 

    @Bean 
    public MongoTemplate mongoTemplate(MongoClient mongo, MongoConverter mongoConverter) throws UnknownHostException { 
     return new MongoTemplate(mongoDbFactory(), mongoConverter); 
    } 

    @Bean 
    public GridFstemplate gridFsTemplate() throws UnknownHostException { 
     return new GridFsTemplate(mongoDbFactory(), mappingMongoConverter()); 
    } 

    @Bean 
    public LocalValidatorFactoryBean localValidatorFactoryBean() { 
     return new LocalValidatorFactoryBean(); 
    } 
} 

堆棧跟蹤

java.lang.IllegalArgumentException: Unsupported entity org.springframework.integration.mongodb.store.MongoDbMessageStore$MessageWrapper! Could not determine IsNewStrategy. 
    at org.springframework.data.support.IsNewStrategyFactorySupport.getIsNewStrategy(IsNewStrategyFactorySupport.java:48) ~[spring-data-commons-1.11.2.RELEASE.jar:na] 
    at org.springframework.data.auditing.IsNewAwareAuditingHandler.markAudited(IsNewAwareAuditingHandler.java:80) ~[spring-data-commons-1.11.2.RELEASE.jar:na] 
    at org.springframework.data.mongodb.core.mapping.event.AuditingEventListener.onApplicationEvent(AuditingEventListener.java:54) ~[spring-data-mongodb-1.8.2.RELEASE.jar:na] 
    at org.springframework.data.mongodb.core.mapping.event.AuditingEventListener.onApplicationEvent(AuditingEventListener.java:31) ~[spring-data-mongodb-1.8.2.RELEASE.jar:na] 
    at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:163) ~[spring-context-4.2.4.RELEASE.jar:4.2.4.RELEASE] 
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:136) ~[spring-context-4.2.4.RELEASE.jar:4.2.4.RELEASE] 
    at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:381) ~[spring-context-4.2.4.RELEASE.jar:4.2.4.RELEASE] 
    at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:335) ~[spring-context-4.2.4.RELEASE.jar:4.2.4.RELEASE] 
    at org.springframework.data.mongodb.core.MongoTemplate.maybeEmitEvent(MongoTemplate.java:1627) ~[spring-data-mongodb-1.8.2.RELEASE.jar:na] 
    at org.springframework.data.mongodb.core.MongoTemplate.doInsert(MongoTemplate.java:799) ~[spring-data-mongodb-1.8.2.RELEASE.jar:na] 
    at org.springframework.data.mongodb.core.MongoTemplate.insert(MongoTemplate.java:743) ~[spring-data-mongodb-1.8.2.RELEASE.jar:na] 
    at org.springframework.integration.mongodb.store.MongoDbMessageStore.addMessageDocument(MongoDbMessageStore.java:220) ~[spring-integration-mongodb-4.2.4.RELEASE.jar:na] 
    at org.springframework.integration.mongodb.store.MongoDbMessageStore.addMessageToGroup(MongoDbMessageStore.java:302) ~[spring-integration-mongodb-4.2.4.RELEASE.jar:na] 
    at org.springframework.integration.handler.DelayHandler.releaseMessageAfterDelay(DelayHandler.java:334) ~[spring-integration-core-4.2.4.RELEASE.jar:na] 
    at org.springframework.integration.handler.DelayHandler.handleRequestMessage(DelayHandler.java:267) ~[spring-integration-core-4.2.4.RELEASE.jar:na] 
    at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.handleMessageInternal(AbstractReplyProducingMessageHandler.java:99) ~[spring-integration-core-4.2.4.RELEASE.jar:na] 
    at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:127) ~[spring-integration-core-4.2.4.RELEASE.jar:na] 
    at org.springframework.integration.dispatcher.AbstractDispatcher.tryOptimizedDispatch(AbstractDispatcher.java:116) ~[spring-integration-core-4.2.4.RELEASE.jar:na] 
    at org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:147) ~[spring-integration-core-4.2.4.RELEASE.jar:na] 
    at org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:120) ~[spring-integration-core-4.2.4.RELEASE.jar:na] 
    at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:77) ~[spring-integration-core-4.2.4.RELEASE.jar:na] 
    at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:442) ~[spring-integration-core-4.2.4.RELEASE.jar:na] 
    at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:392) ~[spring-integration-core-4.2.4.RELEASE.jar:na] 
    at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:115) ~[spring-messaging-4.2.4.RELEASE.jar:4.2.4.RELEASE] 
    at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:45) ~[spring-messaging-4.2.4.RELEASE.jar:4.2.4.RELEASE] 
    at org.springframework.messaging.core.AbstractMessageSendingTemplate.send(AbstractMessageSendingTemplate.java:105) ~[spring-messaging-4.2.4.RELEASE.jar:4.2.4.RELEASE] 
    at org.springframework.integration.handler.AbstractMessageProducingHandler.sendOutput(AbstractMessageProducingHandler.java:231) ~[spring-integration-core-4.2.4.RELEASE.jar:na] 
    at org.springframework.integration.handler.AbstractMessageProducingHandler.produceOutput(AbstractMessageProducingHandler.java:154) ~[spring-integration-core-4.2.4.RELEASE.jar:na] 
    at org.springframework.integration.handler.AbstractMessageProducingHandler.sendOutputs(AbstractMessageProducingHandler.java:102) ~[spring-integration-core-4.2.4.RELEASE.jar:na] 
    at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.handleMessageInternal(AbstractReplyProducingMessageHandler.java:105) ~[spring-integration-core-4.2.4.RELEASE.jar:na] 
    at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:127) ~[spring-integration-core-4.2.4.RELEASE.jar:na] 
    at org.springframework.integration.dispatcher.AbstractDispatcher.tryOptimizedDispatch(AbstractDispatcher.java:116) ~[spring-integration-core-4.2.4.RELEASE.jar:na] 
    at org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:147) ~[spring-integration-core-4.2.4.RELEASE.jar:na] 
    at org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:120) ~[spring-integration-core-4.2.4.RELEASE.jar:na] 
    at org.springframework.integration.amqp.channel.AbstractSubscribableAmqpChannel$DispatchingMessageListener.onMessage(AbstractSubscribableAmqpChannel.java:181) ~[spring-integration-amqp-4.2.4.RELEASE.jar:na] 
    at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:800) [spring-rabbit-1.5.3.RELEASE.jar:na] 
    at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:691) [spring-rabbit-1.5.3.RELEASE.jar:na] 
    at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.access$001(SimpleMessageListenerContainer.java:93) [spring-rabbit-1.5.3.RELEASE.jar:na] 
    at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$1.invokeListener(SimpleMessageListenerContainer.java:183) ~[spring-rabbit-1.5.3.RELEASE.jar:na] 
    at sun.reflect.GeneratedMethodAccessor178.invoke(Unknown Source) ~[na:na] 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_40] 
    at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_40] 
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:302) ~[spring-aop-4.2.4.RELEASE.jar:4.2.4.RELEASE] 
    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190) [spring-aop-4.2.4.RELEASE.jar:4.2.4.RELEASE] 
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) [spring-aop-4.2.4.RELEASE.jar:4.2.4.RELEASE] 
    at org.springframework.retry.interceptor.RetryOperationsInterceptor$1.doWithRetry(RetryOperationsInterceptor.java:74) ~[spring-retry-1.1.2.RELEASE.jar:na] 
    at org.springframework.retry.support.RetryTemplate.doExecute(RetryTemplate.java:263) [spring-retry-1.1.2.RELEASE.jar:na] 
    at org.springframework.retry.support.RetryTemplate.execute(RetryTemplate.java:168) [spring-retry-1.1.2.RELEASE.jar:na] 
    at org.springframework.retry.interceptor.RetryOperationsInterceptor.invoke(RetryOperationsInterceptor.java:98) [spring-retry-1.1.2.RELEASE.jar:na] 
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) [spring-aop-4.2.4.RELEASE.jar:4.2.4.RELEASE] 
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:208) [spring-aop-4.2.4.RELEASE.jar:4.2.4.RELEASE] 
    at com.sun.proxy.$Proxy213.invokeListener(Unknown Source) [na:na] 
    at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.invokeListener(SimpleMessageListenerContainer.java:1358) [spring-rabbit-1.5.3.RELEASE.jar:na] 
    at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.executeListener(AbstractMessageListenerContainer.java:661) [spring-rabbit-1.5.3.RELEASE.jar:na] 
    at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.doReceiveAndExecute(SimpleMessageListenerContainer.java:1102) [spring-rabbit-1.5.3.RELEASE.jar:na] 
    at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.receiveAndExecute(SimpleMessageListenerContainer.java:1086) [spring-rabbit-1.5.3.RELEASE.jar:na] 
    at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.access$1100(SimpleMessageListenerContainer.java:93) [spring-rabbit-1.5.3.RELEASE.jar:na] 
    at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.run(SimpleMessageListenerContainer.java:1203) [spring-rabbit-1.5.3.RELEASE.jar:na] 
    at java.lang.Thread.run(Unknown Source) [na:1.8.0_40] 

回答

0

嗯,看起來像是已經在Spring MongoDB中的數據(或共同)被改變。

請提出一個JIRA關於此事,並將調查該怎麼做。

但它看起來像當前的Spring Data,我們將無法做到Spring Integration方面的任何事情。

同時考慮使用ConfigurableMongoDbMessageStore代替,並注入了一些自定義的Converter一個mappingMongoConverter()Message

public static class MessageReadConverter implements Converter<DBObject, Message<?>> { 

    @Override 
    @SuppressWarnings("unchecked") 
    public Message<?> convert(DBObject source) { 
     return MessageBuilder.withPayload(source.get("payload")).copyHeaders((Map<String, ?>) source.get("headers")).build(); 
    } 

} 

... 
@Bean 
public CustomConversions customConversions() { 
    return new CustomConversions(Collections.singletonList(new MessageReadConverter())); 
} 

至少這是像我和春天有引導,其中MappingMongoConverterMongoDataAutoConfiguration爲我提供:

@Bean 
@ConditionalOnMissingBean(MongoConverter.class) 
public MappingMongoConverter mappingMongoConverter(MongoDbFactory factory, 
     MongoMappingContext context, BeanFactory beanFactory) { 
    DbRefResolver dbRefResolver = new DefaultDbRefResolver(factory); 
    MappingMongoConverter mappingConverter = new MappingMongoConverter(dbRefResolver, 
      context); 
    try { 
     mappingConverter 
       .setCustomConversions(beanFactory.getBean(CustomConversions.class)); 
    } 
    catch (NoSuchBeanDefinitionException ex) { 
     // Ignore 
    } 
    return mappingConverter; 
} 
+0

另請參見Spring集成Java DSL中對MongoDbTests的更改:https://github.com/spring-projects/spring-integration-java-dsl/commit/7029e299e2590d9e44b1dab4c5206f13b2b61626 –

+0

我提交了[JIRA](https://jira.spring.io/browse/INT-4082)。我會着眼於實施您的建議更改。謝謝! –

+0

檢查http://stackoverflow.com/questions/31367714/enablemongoauditing-for-mongodb-on-cloud-foundry-mongolab – derekdata

相關問題