简体   繁体   中英

Spring Cloud Contract - NullPointerException in resolvedDestination

I am trying to create Spring cloud contract for Spring cloud stream. I have source, processor and sink. The source uses SourcePollingChannelAdapte. The contract groovy file looks like this:

package contracts.messaging

import org.springframework.cloud.contract.spec.Contract


Contract.make {
    description("""
Sends a non XhubJobState in Message

""")
    // Label by means of which the output message can be triggered
    label 'accpetable_message'
    // input to the contract
    input {
        // the contract will be triggered by a method
        triggeredBy('verifyValidXhubJobState()')
    }
    // output message of the contract
    outputMessage {
        // destination to which the output message will be sent
        sentTo 'verifications'
        // the body of the output message
        body([
                jobName:"Invalid_Destinations"              
        ])
    }
}

When try to do maven install I get the exception:

"Exception took place while trying to resolve the destination. Will assume the name [verifications]
java.lang.NullPointerException: null
    at org.springframework.cloud.contract.verifier.messaging.stream.StreamStubMessages.resolvedDestination(StreamStubMessages.java:89)......."

I have defined following propery set in application.properties file

"spring.cloud.stream.bindings.output.destination= verifications"

Am I missing something in the configuration?

I haven't seen your code but I can only guess that in your base class you're missing these annotations - https://github.com/spring-cloud-samples/spring-cloud-contract-samples/blob/master/producer/src/test/java/com/example/BeerMessagingBase.java#L14-L19 . Your context wasn't started so the fields weren't injected, that's why you get NPE.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM