问题
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.
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
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
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).
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.
Any help would be appreciated.
Thank you
EDIT: I'm using Spring XD 1.2.1.RELEASE
回答1:
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.
来源:https://stackoverflow.com/questions/32544256/springxd-classcastexception-of-same-class-between-modules-in-a-stream