Skip to content

Conversation

@schmidthappens
Copy link

@schmidthappens schmidthappens commented Dec 8, 2025

Add Spring Framework 7.0 and Spring Boot 4.0 Support

Overview

This PR adds comprehensive support for Spring Framework 7.0 and Spring Boot 4.0 to pact-jvm, enabling developers to use the latest Spring ecosystem while maintaining full contract testing capabilities.
Therefore the changes are inspired by the latest provider module for Spring Framework 6.0.

Note

This PR builds on top of branch 4.7.x as there is already Kotlin 2.2.0 supported which is a minimum requirement for Spring 7 (see: https://github.com/spring-projects/spring-framework/wiki/Spring-Framework-7.0-Release-Notes)

Key Features

New Spring 7 Module (provider:spring7)

  • Spring7MockMvcTestTarget: Full MockMvc test support for Spring 7.x
  • API Compatibility: Updated to use Spring 7 APIs (e.g., HttpHeaders.containsHeader())
  • Async Support: Complete support for DeferredResult and async request processing
  • Multipart Uploads: Enhanced multipart file upload handling with Spring 7 improvements

Spring Boot 4.0 Integration

  • Updated Test Configuration: Compatible with Spring Boot 4.0 test slices and security configuration
  • Updated Import Paths: Uses new Spring Boot 4.0 package structure (org.springframework.boot.webmvc.test.autoconfigure.WebMvcTest)
  • Test Infrastructure: Full JUnit 5 and Spock test coverage

Technical Implementation

Core Components

  • Spring7MockMvcTestTarget: Main test target implementation for Spring 7
  • Updated dependencies to Spring Framework 7.0.1 and Spring Boot 4.0.0
  • Backward compatibility maintained with existing pact-jvm APIs

Test Coverage

  • Java Tests: MockMvcTestTargetWebMvcTestJava with proper security configuration
  • Kotlin Tests: MockMvcTestTargetWebMvcTest with Kotlin DSL support
  • Groovy Tests: MockMvcTestWithCookieSpec with cookie handling
  • WebFlux Tests: WebFluxTargetSpec for reactive applications
  • Async Tests: Full DeferredResult and CompletableFuture support

Spring Boot 4.0 Migration Considerations

  • Updated test configuration to use @Import(SecurityTestConfiguration.class) for proper Spring Boot 4.0 test context loading
  • Compatible with Spring Boot 4.0's updated test slice architecture
  • Proper handling of static inner controller classes in test scenarios

Requirements

  • JDK 17+ (required for Spring 7)
  • Gradle 8.11+ (for proper Kotlin 2.2 and Java 21 support)
  • Spring Framework 7.0.1+
  • Spring Boot 4.0.0+

Testing

All existing tests pass, plus new Spring 7-specific test coverage:

./gradlew :provider:spring7:test

🔄 Migration Path

For New Projects

<dependency>
    <groupId>au.com.dius.pact.provider</groupId>
    <artifactId>spring7</artifactId>
    <version>${pact.version}</version>
</dependency>

For Existing Spring 6 Projects

The API is fully compatible - simply change your dependency from spring6 to spring7:

// Before
context.setTarget(Spring6MockMvcTestTarget(mockMvc))

// After
context.setTarget(Spring7MockMvcTestTarget(mockMvc))

@rholshausen
Copy link
Contributor

Awesome PR, thank you! I'll release a new version of the 4.7.x branch.

@rholshausen rholshausen merged commit fa9f351 into pact-foundation:v4.7.x Dec 9, 2025
70 of 82 checks passed
@YOU54F
Copy link
Member

YOU54F commented Dec 10, 2025

thanks @schmidthappens, this is an excellent pr and great contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants