Does CoApi Support Spring Boot 3.x? Version Compatibility and Setup Guide
Yes, CoApi fully supports Spring Boot 3.x through the 1.x release line, with CoApi 1.x specifically targeting Spring Boot 3.2.x and earlier 3.x versions.
CoApi is a lightweight HTTP client framework for Spring Boot applications that leverages Spring 6's HTTP Interface. If you are working with Spring Boot 3.x and need a declarative way to define HTTP clients, understanding CoApi's version compatibility is essential for seamless integration into the ahoo-wang/coapi ecosystem.
Spring Boot Version Compatibility Matrix
According to the README.md in the ahoo-wang/coapi repository, CoApi maintains separate release lines for different Spring Boot generations:
| CoApi Version | Supported Spring Boot Version |
|---|---|
| 1.x | Spring Boot 3.2.x (and earlier 3.x releases) |
| 2.x | Spring Boot 4.x (future major releases) |
The CoApi 1.x series works out-of-the-box with Spring Boot 3.x projects, utilizing the Spring Framework 6 HTTP Interface introduced in Spring Boot 3.0. When Spring Boot 4.x becomes generally available, the CoApi 2.x series will provide forward compatibility.
Setting Up CoApi with Spring Boot 3.x
To integrate CoApi into a Spring Boot 3.x application, follow these implementation steps using the artifacts defined in spring-boot-starter/build.gradle.kts.
Add the Starter Dependency
Include the CoApi Spring Boot starter in your build configuration. For Gradle Kotlin DSL:
dependencies {
implementation("me.ahoo.coapi:coapi-spring-boot-starter:${"$"}{coapi.version}")
}
Enable Auto-Configuration
Bootstrap CoApi by adding the @EnableCoApi annotation to your main application class. This annotation, defined in spring/src/main/kotlin/me/ahoo/coapi/spring/EnableCoApi.kt, registers your client interfaces as Spring beans:
import me.ahoo.coapi.spring.EnableCoApi
import org.springframework.boot.autoconfigure.SpringBootApplication
@EnableCoApi(clients = [GitHubApiClient::class])
@SpringBootApplication
class DemoApplication
Define a CoApi Client Interface
Create an interface annotated with @CoApi from api/src/main/kotlin/me/ahoo/coapi/api/CoApi.kt to declare your HTTP endpoints:
import me.ahoo.coapi.annotation.CoApi
import org.springframework.web.service.annotation.GetExchange
import org.springframework.web.bind.annotation.PathVariable
import reactor.core.publisher.Flux
@CoApi(baseUrl = "\${github.url}")
interface GitHubApiClient {
@GetExchange("repos/{owner}/{repo}/issues")
fun listIssues(
@PathVariable owner: String,
@PathVariable repo: String
): Flux<Issue>
}
Consume the Client
Inject the client interface into your controllers or services. The full runnable example is available in example/example-consumer-server/src/main/kotlin/me/ahoo/coapi/example/consumer/ConsumerServer.kt:
import org.springframework.web.bind.annotation.RestController
import org.springframework.web.bind.annotation.GetMapping
import reactor.core.publisher.Flux
@RestController
class GithubController(private val gitHubApiClient: GitHubApiClient) {
@GetMapping("/issues")
fun issues(): Flux<Issue> =
gitHubApiClient.listIssues("ahoo-wang", "coapi")
}
Key Source Files and Implementation Details
Understanding the core architecture helps when debugging or extending CoApi:
spring-boot-starter/build.gradle.kts– Defines the starter artifact that brings in all required dependencies for Spring Boot 3.x auto-configuration.spring/src/main/kotlin/me/ahoo/coapi/spring/EnableCoApi.kt– Contains the@EnableCoApiannotation that triggers the client registration process through Spring's component scanning.api/src/main/kotlin/me/ahoo/coapi/api/CoApi.kt– Houses the core@CoApiannotation used to specifybaseUrland other client-level configurations.
Summary
- CoApi 1.x fully supports Spring Boot 3.2.x and all earlier Spring Boot 3.x releases.
- Add
coapi-spring-boot-starterto your dependencies for auto-configuration. - Use
@EnableCoApiin your main application class to register client interfaces. - Define clients using the
@CoApiannotation with Spring 6's HTTP Interface methods. - Plan to upgrade to CoApi 2.x when migrating to Spring Boot 4.x in the future.
Frequently Asked Questions
Which CoApi version should I use with Spring Boot 3.2?
Use CoApi 1.x for any Spring Boot 3.x application, including version 3.2. The 1.x release line is specifically built and tested against Spring Boot 3.2.x and earlier 3.x versions, ensuring full compatibility with Spring Framework 6.
Is CoApi compatible with Spring Boot 3.0 and 3.1?
Yes, CoApi 1.x supports all Spring Boot 3.x versions starting from 3.0. Since CoApi relies on the Spring 6 HTTP Interface introduced in Spring Boot 3.0, it remains compatible across the entire 3.x generation without requiring version-specific configuration.
How do I migrate from CoApi 1.x to 2.x when Spring Boot 4.x releases?
When Spring Boot 4.x becomes available, upgrade your dependency version to CoApi 2.x. The project documentation in README.md will provide specific migration notes, but the core annotation-based programming model using @CoApi and @EnableCoApi is expected to remain consistent between major versions.
Does CoApi require any specific Spring Framework version?
CoApi 1.x requires Spring Framework 6.x, which is bundled with Spring Boot 3.x. The framework leverages the HTTP Interface feature introduced in Spring 6, making it incompatible with Spring Boot 2.x and Spring Framework 5.x.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →