Skip to content

Feat: Add Spring Boot AutoConfiguration#260

Open
vitinh0z wants to merge 4 commits intospotify:masterfrom
vitinh0z:feature/spring-boot-autoconfig
Open

Feat: Add Spring Boot AutoConfiguration#260
vitinh0z wants to merge 4 commits intospotify:masterfrom
vitinh0z:feature/spring-boot-autoconfig

Conversation

@vitinh0z
Copy link

Description

This PR introduces Spring Boot AutoConfiguration to the library.
It automatically registers the GithubApiModule bean when the library is used in a Spring Boot application that has Jackson on the classpath.

Resolves

Closes #61

Changes

  • Added optional dependencies for spring-boot-autoconfigure (v2.7.18 for Java 11 compatibility).
  • Added GithubClientAutoConfiguration to conditionally register the GithubApiModule bean.
  • Registered the configuration in META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports.
  • Added GithubClientAutoConfigurationTest using ApplicationContextRunner to verify the behavior.

Verification

  • Ran mvn clean install -DskipTests locally -> BUILD SUCCESS.
  • Ran mvn test locally -> All tests passed.

Copilot AI review requested due to automatic review settings March 23, 2026 11:51
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aims to add Spring Boot AutoConfiguration support so the library self-registers required beans when used in a Spring Boot app (per #61), reducing manual Jackson setup.

Changes:

  • Adds optional Spring Boot AutoConfiguration dependencies (Boot 2.7.18) and Boot test support.
  • Introduces GithubClientAutoConfiguration and a corresponding ApplicationContextRunner test.
  • Adds an AutoConfiguration.imports resource intended to register the auto-configuration.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.

File Description
pom.xml Adds Spring Boot autoconfigure (+ processor) dependencies and Boot test dependency.
src/main/java/com/spotify/github/v3/spring/GithubClientAutoConfiguration.java Adds a new Spring Boot auto-configuration class (currently wiring a GitHubClient bean).
src/test/java/com/spotify/github/v3/spring/GithubClientAutoConfigurationTest.java Adds a Spring Boot context-runner test intended to validate module registration behavior.
src/test/resources/META-INF/Spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports Adds an imports file intended for Boot’s auto-configuration discovery (currently under test resources and with incorrect casing).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +24 to +37
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Bean;

import com.spotify.github.v3.clients.GitHubClient;

@AutoConfiguration
@ConditionalOnClass(GitHubClient.class)
public class GithubClientAutoConfiguration {

@Bean
@ConditionalOnBean
public GitHubClient gitHubClient() {
return GitHubClient.create(null, null);
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This auto-configuration doesn’t match the PR goal (registering a GithubApiModule/Jackson Module). It currently creates a GitHubClient bean using GitHubClient.create(null, null), which leaves required constructor inputs (e.g., baseUrl/token) null and can lead to runtime failures when the client is used. Consider changing this configuration to expose a GithubApiModule bean (and only if Jackson is present, and if no user-defined module bean already exists) rather than instantiating a client with null parameters.

Suggested change
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Bean;
import com.spotify.github.v3.clients.GitHubClient;
@AutoConfiguration
@ConditionalOnClass(GitHubClient.class)
public class GithubClientAutoConfiguration {
@Bean
@ConditionalOnBean
public GitHubClient gitHubClient() {
return GitHubClient.create(null, null);
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import com.fasterxml.jackson.databind.Module;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.spotify.github.v3.GithubApiModule;
import com.spotify.github.v3.clients.GitHubClient;
@AutoConfiguration
@ConditionalOnClass({GitHubClient.class, ObjectMapper.class, Module.class})
public class GithubClientAutoConfiguration {
@Bean
@ConditionalOnMissingBean(Module.class)
public Module githubApiModule() {
return new GithubApiModule();

Copilot uses AI. Check for mistakes.
Comment on lines +34 to +36
@Bean
@ConditionalOnBean
public GitHubClient gitHubClient() {
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ConditionalOnBean is used without specifying any bean types/names. In Spring Boot this condition is effectively ambiguous and can behave unexpectedly (or not match at all). If the intent is to only enable the bean when a specific dependency is present (e.g., ObjectMapper), specify that explicitly (or use @ConditionalOnClass / @ConditionalOnMissingBean as appropriate).

Copilot uses AI. Check for mistakes.

package com.spotify.github.v3.spring;

import org.junit.Test;
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The project’s existing tests use JUnit Jupiter (org.junit.jupiter.api.Test), but this new test uses JUnit 4 (org.junit.Test). This can cause the test not to run (or require vintage support) and is inconsistent with the repo’s current test framework.

Suggested change
import org.junit.Test;
import org.junit.jupiter.api.Test;

Copilot uses AI. Check for mistakes.
Comment on lines +39 to +45
public void testModuleIsRegistered(){

this.contextRunner
.withUserConfiguration(JacksonConfig.class)
.run((context) -> {
assertThat(context).hasSingleBean(GithubApiModule.class);
});
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test asserts that a GithubApiModule bean is registered by GithubClientAutoConfiguration, but the auto-configuration currently defines a GitHubClient bean instead. As written, this test will fail unless some other configuration is providing GithubApiModule; align the test assertions with the actual auto-configured bean(s), or update the auto-configuration to register GithubApiModule as described in the PR.

Copilot uses AI. Check for mistakes.
@@ -0,0 +1 @@
com.spotify.github.v3.spring.GithubClientAutoConfiguration No newline at end of file
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spring Boot discovers auto-configurations from META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports in main resources. This file is currently under src/test/resources and uses META-INF/Spring (capital S), so it won’t be found in real applications (and may not be found on case-sensitive filesystems). Move it to src/main/resources/META-INF/spring/ with the correct casing to actually enable the auto-configuration.

Copilot uses AI. Check for mistakes.
Comment on lines +124 to +129
<artifactId>spring-boot-autoconfigure-processor</artifactId>
<version>2.7.18</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spring-boot-autoconfigure-processor is an annotation processor; however, the maven-compiler-plugin config in this POM uses annotationProcessorPaths and only lists Immutables. If you expect Spring’s autoconfigure metadata to be generated, add the processor to annotationProcessorPaths (or otherwise ensure it’s on the annotation processor path); otherwise this dependency is likely unused.

Suggested change
<artifactId>spring-boot-autoconfigure-processor</artifactId>
<version>2.7.18</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>

Copilot uses AI. Check for mistakes.
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.

Spring Boot config

2 participants