Spring Cloud 生成的存根的新结构
2024-01-03 17:35 更新
在1.1.x
中,我们对生成的存根的结构进行了更改。如果您一直使用@AutoConfigureWireMock
表示法来使用类路径中的存根,那么它将不再起作用。以下示例显示了@AutoConfigureWireMock
表示法的工作原理:
@AutoConfigureWireMock(stubs = "classpath:/customer-stubs/mappings", port = 8084)
您必须将存根的位置更改为:classpath:…/META-INF/groupId/artifactId/version/mappings
或使用新的基于类路径的@AutoConfigureStubRunner
,如以下示例所示:
@AutoConfigureWireMock(stubs = "classpath:customer-stubs/META-INF/travel.components/customer-contract/1.0.2-SNAPSHOT/mappings/", port = 8084)
如果您不想使用@AutoConfigureStubRunner
,并且希望保留原来的结构,请相应地设置插件任务。以下示例适用于前一片段中介绍的结构。
Maven.
<!-- start of pom.xml --> <properties> <!-- we don't want the verifier to do a jar for us --> <spring.cloud.contract.verifier.skip>true</spring.cloud.contract.verifier.skip> </properties> <!-- ... --> <!-- You need to set up the assembly plugin --> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-assembly-plugin</artifactId> <executions> <execution> <id>stub</id> <phase>prepare-package</phase> <goals> <goal>single</goal> </goals> <inherited>false</inherited> <configuration> <attach>true</attach> <descriptor>$../../../../src/assembly/stub.xml</descriptor> </configuration> </execution> </executions> </plugin> </plugins> </build> <!-- end of pom.xml --> <!-- start of stub.xml--> <assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 https://maven.apache.org/xsd/assembly-1.1.3.xsd"> <id>stubs</id> <formats> <format>jar</format> </formats> <includeBaseDirectory>false</includeBaseDirectory> <fileSets> <fileSet> <directory>${project.build.directory}/snippets/stubs</directory> <outputDirectory>customer-stubs/mappings</outputDirectory> <includes> <include>**/*</include> </includes> </fileSet> <fileSet> <directory>$../../../../src/test/resources/contracts</directory> <outputDirectory>customer-stubs/contracts</outputDirectory> <includes> <include>**/*.groovy</include> </includes> </fileSet> </fileSets> </assembly> <!-- end of stub.xml-->
Gradle.
task copyStubs(type: Copy, dependsOn: 'generateWireMockClientStubs') { // Preserve directory structure from 1.0.X of spring-cloud-contract from "${project.buildDir}/resources/main/customer-stubs/META-INF/${project.group}/${project.name}/${project.version}" into "${project.buildDir}/resources/main/customer-stubs" }
以上内容是否对您有帮助:
更多建议: