使用spring cloud合同时APi不兼容

时间:2018-06-15 12:16:33

标签: spring-cloud-contract

我试图在样本生产者项目中使用spring cloud合约。但是由于

,我在POM中看到了错误
Multiple annotations found at this line:
    - Execution default-generateTests of goal org.springframework.cloud:spring-cloud-contract-maven-plugin:1.2.4.RELEASE:generateTests failed: An API 
     incompatibility was encountered while executing org.springframework.cloud:spring-cloud-contract-maven-plugin:1.2.4.RELEASE:generateTests: 
     java.lang.VerifyError: Bad <init> method call from inside of a branch Exception Details: Location: org/springframework/cloud/contract/verifier/
     TestGenerator.<init>(Lorg/springframework/cloud/contract/verifier/config/ContractVerifierConfigProperties;)V @75: invokespecial Reason: Error exists in the 
     bytecode Bytecode: 0000000: b800 244d b800 2a9a 0006 a700 472a 2b2c 0000010: 122b 3212 02b9 0031 0200 1233 b800 39c0 0000020: 0033 2c12 
     3a32 123c 2c12 3d32 2bb9 0041 0000030: 0200 2c12 4232 1202 b900 3102 002b b900 0000040: 4605 0012 3cb8 0039 c000 3cb7 0049 a700 
     0000050: 2c2a 2bb8 004d 2c12 4e32 123c 2c12 4f32 0000060: 2bb9 0041 0200 b800 4d2b b900 4605 0012 0000070: 3cb8 0039 c000 3cb7 0049 b1 
     Stackmap Table: append_frame(@13,Object[#83])

我正在使用Spring Boot 1.5.14.RELEASE,Edgware.SR3,Java 1.8和spring-cloud-contract-maven-plugin 1.2.4.RELEASE

我已经尝试使用插件的版本,Spring云和spring boot,使用在线教程中的示例进行spring-cloud-contract但我似乎无法摆脱不兼容性错误。< / p>

我的代码在这里 - https://github.com/craigmgordon/spring-cloud-contract/tree/Phase2/creditcheckservice-producer如果有帮助

1 个答案:

答案 0 :(得分:0)

我成功地建立了你的项目。你的合同中有一个错误(引用太多)

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

Contract.make{
    request{
        method 'POST'
        url '/credit-scores'
        body """
            {
                "citizenNumber" : 1234
            }
            """ // you had an extra quote here
        headers{
            contentType applicationJson()
        }
    }
    response{
        status 200
        body """
            {
                "score" : "HIGH"
            }
            """
        headers{
            contentType applicationJson()
        }
    }
}

执行

➜  creditcheckservice-producer git:(Phase2) ✗ ./mvnw clean install
...
Results :

Tests in error:
  CreditcardserviceTest.validate_shouldGrantACreditScoreOfHighToACitizen:24 » IllegalState

Tests run: 2, Failures: 0, Errors: 1, Skipped: 0

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 7.711 s
[INFO] Finished at: 2018-06-15T14:36:14+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.18.1:test (default-test) on project creditcheckservice-producer: There are test failures.
[ERROR]
[ERROR] Please refer to /Users/marcingrzejszczak2/repo/contract-issues/so/foo/spring-cloud-contract/creditcheckservice-producer/target/surefire-reports for the individual test results.
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

更新:

原来,java版本中存在不匹配