Skip to content
This repository has been archived by the owner on May 31, 2022. It is now read-only.

@ConditionalOnBean(ClientRegistrationService::class) fails to match JdbcClientDetailsService #1700

Open
ofir-popowski opened this issue Jun 6, 2019 · 0 comments

Comments

@ofir-popowski
Copy link

ofir-popowski commented Jun 6, 2019

In an auto-configuration library internally developed, I'm writing a REST controller that exposes CRUD operations based on the type of OAuth2 services beans that are found, something like this:

  @Bean
  @ConditionalOnBean(ClientDetailsService::class)
  fun clientServiceController(
    clientDetailsService: ClientDetailsService
  ): ClientDetailsServiceController {
    return ClientDetailsServiceController(clientDetailsService)
  }

  @Bean
  @ConditionalOnBean(ClientRegistrationService::class)
  fun clientRegistrationServiceController(
    clientRegistrationService: ClientRegistrationService
  ): ClientRegistrationServiceController {
    return ClientRegistrationServiceController(clientRegistrationService)
  }

I want to only register a controller that exposes ClientDetailsService#loadClientByClientId if we do not have a ClientRegistrationService, and if we do have a registration service, to additionally register a controller that performs all other operations from that interface.

One of our modules that registers these controllers, also registers a JdbcClientDetailsService bean, which implements both interfaces. Yet, the @ConditionalOnBean(ClientRegistrationService::class) fails to match it, so only the first bean is created by not the second.

This is an example of how we declare the JdbcClientDetailsService:

  @Bean
  fun jdbcClientDetailsService(
    passwordEncoder: PasswordEncoder,
    dataSource: DataSource): JdbcClientDetailsService {

    return JdbcClientDetailsService(dataSource).apply { setPasswordEncoder(passwordEncoder) }
  }

The odd thing is that autowiring a ClientRegistrationService does successfully inject JdbcClientDetailsService.

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

No branches or pull requests

2 participants