SpringXD:流中模块之间相同类的ClassCastException [英] SpringXD: ClassCastException of same class between modules in a stream

查看:151
本文介绍了SpringXD:流中模块之间相同类的ClassCastException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义的Spring XD源模块,该模块将Spring Social用于Twitter并输出Tweet对象.这很好用.我可以记录源的输出并查看列出的Tweet对象.我可以将该流的源输出类型更改为application/json,以查看JSON的输出.这可以按预期工作.

I have a custom Spring XD source module that uses Spring Social for Twitter and outputs Tweet objects. This is working just fine. I can log the output of the source and see the Tweet objects listed. I can change the output type of the source for that stream to application/json to see the output at JSON. This works as expected.

然后,我创建了一个处理器模块,该模块将从该Tweet创建一个新对象并将其输出.转换消息需要一个包含Tweet对象作为其有效载荷的GenericMessage(我也尝试过将方法参数设为Tweet,但这也没有用).

I then created a processor module that will create a new object from that Tweet and output it. The transform message expects a GenericMessage containing a Tweet object as its payload (I've also tried having the method argument be just the Tweet, but that also didnt work).

@Transformer
public OtherThing<Tweet> transform(GenericMessage<Tweet> message) {
    // ... snip ...
}

但是,当我将两个模块链接在一起时

However, when i link the two modules together

stream create --name test --definition 'my-tweet-source-module | my-tweet-processor | log' --deploy

并且从源模块输出一条Tweet,我得到一个类强制转换异常:

and a Tweet is output from the source module, i get a class cast exception:

java.lang.ClassCastException: org.springframework.social.twitter.api.Tweet cannot be cast to org.springframework.social.twitter.api.Tweet

我已经验证了两个模块都使用相同版本的Spring Social Twitter,所以那里应该没有问题.当前,这些模块正在通过本地传输进行通信,因此也不应该是任何类加载问题(它们最终将需要通过非本地传输进行通信).

I've verified that both modules are using the same version of Spring Social Twitter so there should be no problem there. Currently, the modules are communicating over local transport, so this shouldn't be any class loading problem either (they will eventually need to communicate over non-local transport).

我也尝试过变通方法,例如在流中定义源模块的输出类型应为application/json,然后尝试从输入字符串有效负载中读取JSON,但是由于Spring Social的性质鸣叫对象,杰克逊不遵守.

I've tried workarounds as well such as defining in the stream that the output type for the source module should be application/json and then try to read the JSON from the input string payload but due to the nature of the Spring Social Tweet object, Jackson doesnt comply.

我想知道为什么会这样,我应该如何解决呢?我觉得我无疑是在做错事.如果我不允许这样做,我想知道为什么会这样,以及应该采取什么适当的措施.

I'm wondering why this is happening and how i should resolve this? I feel that i'm undoubtedly doing something wrong. If i'm not allowed to do this, i'd like to know why that is and what the appropriate thing to do is.

任何帮助将不胜感激.

谢谢

编辑:我正在使用Spring XD 1.2.1.RELEASE

EDIT: I'm using Spring XD 1.2.1.RELEASE

推荐答案

请参见强制转换为同一类时出现ClassCastException .几乎可以肯定这是一个类加载器问题.尝试从模块的类路径中删除spring-social并将其添加到xd/lib中,以便由同一类加载器加载.

See ClassCastException when casting to the same class . This is almost certainly a class loader issue. Try removing spring-social from the modules' class path and add it to xd/lib so it's loaded by the same class loader.

这篇关于SpringXD:流中模块之间相同类的ClassCastException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆