Spring Boot Version 3.5.7

Describe the bug Suppose we have

public class CustomBaseJpaRepositoryFactoryBean<T extends Repository<S, ID>, S, ID> extends JpaRepositoryFactoryBean<T, S, ID> {

    private final ApplicationContext applicationContext;

    public CustomBaseJpaRepositoryFactoryBean(Class<? extends T> repositoryInterface, ApplicationContext applicationContext) {
        super(repositoryInterface);
        this.applicationContext = applicationContext;
    }

    @Override
    protected RepositoryFactorySupport createRepositoryFactory(EntityManager entityManager) {
        return new CustomBaseJpaRepositoryFactory(entityManager, applicationContext);
    }
}

If we have in pom

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-oauth2-client</artifactId>
        </dependency>

Then the application won't start. Here are logs:

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/

 :: Spring Boot ::                (v3.5.7)

2025-11-14T21:55:26.805+01:00  INFO 26818 --- [custom-simple-jpa-repository-constructor-injection-bug] [           main] sitoryConstructorInjectionBugApplication : Starting CustomSimpleJpaRepositoryConstructorInjectionBugApplication using Java 21.0.5 with PID 26818 (/home/matevskial/Privy/dev/custom-simple-jpa-repository-constructor-injection-bug/target/classes started by matevskial in /home/matevskial/Privy/dev/custom-simple-jpa-repository-constructor-injection-bug)
2025-11-14T21:55:26.806+01:00  INFO 26818 --- [custom-simple-jpa-repository-constructor-injection-bug] [           main] sitoryConstructorInjectionBugApplication : No active profile set, falling back to 1 default profile: "default"
2025-11-14T21:55:27.066+01:00  INFO 26818 --- [custom-simple-jpa-repository-constructor-injection-bug] [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2025-11-14T21:55:27.094+01:00  INFO 26818 --- [custom-simple-jpa-repository-constructor-injection-bug] [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 23 ms. Found 1 JPA repository interface.
2025-11-14T21:55:27.247+01:00  WARN 26818 --- [custom-simple-jpa-repository-constructor-injection-bug] [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'someRepository' defined in com.matevskial.customsimplejparepositoryconstructorinjectionbug.customsimplejparepositoryconstructorinjectionbug.SomeRepository defined in @EnableJpaRepositories declared on CustomSimpleJpaRepositoryConstructorInjectionBugApplication: Unsatisfied dependency expressed through constructor parameter 1: Ambiguous argument values for parameter of type [org.springframework.context.ApplicationContext] - did you specify the correct bean references as arguments?
2025-11-14T21:55:27.251+01:00  INFO 26818 --- [custom-simple-jpa-repository-constructor-injection-bug] [           main] .s.b.a.l.ConditionEvaluationReportLogger : 

Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled.
2025-11-14T21:55:27.259+01:00 ERROR 26818 --- [custom-simple-jpa-repository-constructor-injection-bug] [           main] o.s.boot.SpringApplication               : Application run failed

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'someRepository' defined in com.matevskial.customsimplejparepositoryconstructorinjectionbug.customsimplejparepositoryconstructorinjectionbug.SomeRepository defined in @EnableJpaRepositories declared on CustomSimpleJpaRepositoryConstructorInjectionBugApplication: Unsatisfied dependency expressed through constructor parameter 1: Ambiguous argument values for parameter of type [org.springframework.context.ApplicationContext] - did you specify the correct bean references as arguments?
    at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:785) ~[spring-beans-6.2.12.jar:6.2.12]
    at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:240) ~[spring-beans-6.2.12.jar:6.2.12]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1395) ~[spring-beans-6.2.12.jar:6.2.12]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1232) ~[spring-beans-6.2.12.jar:6.2.12]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getSingletonFactoryBeanForTypeCheck(AbstractAutowireCapableBeanFactory.java:1034) ~[spring-beans-6.2.12.jar:6.2.12]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getTypeForFactoryBean(AbstractAutowireCapableBeanFactory.java:916) ~[spring-beans-6.2.12.jar:6.2.12]
    at org.springframework.beans.factory.support.AbstractBeanFactory.isTypeMatch(AbstractBeanFactory.java:664) ~[spring-beans-6.2.12.jar:6.2.12]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doGetBeanNamesForType(DefaultListableBeanFactory.java:652) ~[spring-beans-6.2.12.jar:6.2.12]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:612) ~[spring-beans-6.2.12.jar:6.2.12]
    at org.springframework.beans.factory.BeanFactoryUtils.beanNamesForTypeIncludingAncestors(BeanFactoryUtils.java:264) ~[spring-beans-6.2.12.jar:6.2.12]
    at org.springframework.security.config.annotation.web.configuration.OAuth2ClientConfiguration$OAuth2AuthorizedClientManagerRegistrar.getBeanNamesForType(OAuth2ClientConfiguration.java:426) ~[spring-security-config-6.5.6.jar:6.5.6]
    at org.springframework.security.config.annotation.web.configuration.OAuth2ClientConfiguration$OAuth2AuthorizedClientManagerRegistrar.postProcessBeanDefinitionRegistry(OAuth2ClientConfiguration.java:190) ~[spring-security-config-6.5.6.jar:6.5.6]
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:349) ~[spring-context-6.2.12.jar:6.2.12]
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:148) ~[spring-context-6.2.12.jar:6.2.12]
    at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:791) ~[spring-context-6.2.12.jar:6.2.12]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:609) ~[spring-context-6.2.12.jar:6.2.12]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146) ~[spring-boot-3.5.7.jar:3.5.7]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:752) ~[spring-boot-3.5.7.jar:3.5.7]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:439) ~[spring-boot-3.5.7.jar:3.5.7]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:318) ~[spring-boot-3.5.7.jar:3.5.7]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1361) ~[spring-boot-3.5.7.jar:3.5.7]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1350) ~[spring-boot-3.5.7.jar:3.5.7]
    at com.matevskial.customsimplejparepositoryconstructorinjectionbug.customsimplejparepositoryconstructorinjectionbug.CustomSimpleJpaRepositoryConstructorInjectionBugApplication.main(CustomSimpleJpaRepositoryConstructorInjectionBugApplication.java:14) ~[classes/:na]


Process finished with exit code 1

To Reproduce

  • Use this minimal reproducible example: https://github.com/matevskial/custom-simple-jpa-repository-constructor-injection-bug

  • Clone the repo

  • Compile: mvn clean package

  • Run the application java -jar target/custom-simple-jpa-repository-constructor-injection-bug-0.0.1-SNAPSHOT.jar

Expected behavior The application should start

Note:

If we use @Autowired instead constructor injection, the application will start normally:

public class CustomBaseJpaRepositoryFactoryBean<T extends Repository<S, ID>, S, ID> extends JpaRepositoryFactoryBean<T, S, ID> {

    @Autowired
    private ApplicationContext applicationContext;

    public CustomBaseJpaRepositoryFactoryBean(Class<? extends T> repositoryInterface) {
        super(repositoryInterface);
    }

    @Override
    protected RepositoryFactorySupport createRepositoryFactory(EntityManager entityManager) {
        return new CustomBaseJpaRepositoryFactory(entityManager, applicationContext);
    }
}

Sample

A link to a GitHub repository with a minimal, reproducible sample.