title: JwtDecoder bean is not injected automatically while setting a ressource server using 'spring-boot-starter-oauth2-resource-server'
body: <p>I am setting a resource server using the 'spring-boot-starter-oauth2-resource-server':</p>
  <pre><code>implementation group: 'org.springframework.boot', name: 'spring-boot-starter-oauth2-resource-server'
  </code></pre>
  <p>I have set a simple Security config  like this:</p>
  <pre><code>@Configuration
  @EnableWebSecurity
  class EndpointsSecurityConfig : WebSecurityConfigurerAdapter() {
  
      override fun configure(web: WebSecurity) {
          web.ignoring().antMatchers(&quot;/live&quot;)
      }
  
      override fun configure(http: HttpSecurity?) {
          http?.cors()
          http?.sessionManagement()?.sessionCreationPolicy(SessionCreationPolicy.STATELESS)
          http?.csrf()?.disable()
          http
              ?.authorizeRequests()
              ?.anyRequest()
              ?.authenticated()
              ?.and()
              ?.oauth2ResourceServer()
              ?.jwt()
      }
  }
  </code></pre>
  <p>And in my application.yml I added the issuer-uri like this :</p>
  <pre><code>spring:
    security:
      oauth2:
        resourceserver:
          jwt:
            issuer-uri: https://cognito-idp.${AWS_REGION:eu-central-1}.amazonaws.com/${COGNITO_USER_POOL_ID:testUserPoolId}
  </code></pre>
  <p>As I have seen in many tutorials and in the official doc this config is minimalistic and should work out of the box without any extra configs, but my application fails to start with the following error :</p>
  <pre><code>Error creating bean with name 'springSecurityFilterChain' defined in class path resource [org/springframework/security/config/annotation/web/configuration/WebSecurityConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.servlet.Filter]: Factory method 'springSecurityFilterChain' threw exception; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.security.oauth2.jwt.JwtDecoder' available
     at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:656)
  </code></pre>
  <p>So the problem here is that the JwtDecoder bean is not found even though it is declared in the OAuth2ResourceServerJwtConfiguration class and is conditioned by the issuer-uri which I have set in my application.yml.</p>
  <p>As a workaround I redeclared the bean myself like this :</p>
  <pre><code>@Configuration
  @EnableWebSecurity
  class EndpointSecurityConfig(@Value(&quot;\${spring.security.oauth2.resourceserver.jwt.issuer-uri}&quot;) private val issuerUri: String) : WebSecurityConfigurerAdapter() {
  
      override fun configure(web: WebSecurity) {
          web.ignoring().antMatchers(&quot;/live&quot;)
      }
  
      override fun configure(http: HttpSecurity?) {
          http?.cors()
          http?.sessionManagement()?.sessionCreationPolicy(SessionCreationPolicy.STATELESS)
          http?.csrf()?.disable()
          http
              ?.authorizeRequests()
              ?.anyRequest()
              ?.authenticated()
              ?.and()
              ?.oauth2ResourceServer()
              ?.jwt()
      }
  
      @Bean
      @Conditional(IssuerUriCondition::class)
      fun jwtDecoderByIssuerUri(): JwtDecoder? {
          return JwtDecoders.fromIssuerLocation(issuerUri)
      }
  }
  </code></pre>
  <p>And this is working, but I couldn't figure out why the out-of-the-box config is not working for me?</p>
  <p><strong>Update: gradle config</strong></p>
  <pre><code>
  plugins {
      id 'java'
      id &quot;io.spring.dependency-management&quot; version &quot;1.0.9.RELEASE&quot;
      id &quot;org.springframework.boot&quot; version &quot;2.2.5.RELEASE&quot;
      id &quot;org.owasp.dependencycheck&quot; version &quot;6.0.2&quot;
  }
  
  // irrelevent details
  
  dependencies {
      ktlint &quot;com.pinterest:ktlint:0.34.2&quot;
  
      implementation group: 'org.jetbrains.kotlin', name: 'kotlin-stdlib-jdk8', version: '1.3.70'
      implementation group: 'org.jetbrains.kotlin', name: 'kotlin-reflect', version: '1.3.70'
      implementation group: 'org.jetbrains.kotlinx', name: 'kotlinx-coroutines-core', version: '1.3.0'
  
      implementation group: 'org.springframework.boot', name: 'spring-boot-starter', version: '2.3.4.RELEASE'
      implementation group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '2.3.4.RELEASE'
      implementation group: 'org.springframework.boot', name: 'spring-boot-starter-log4j2', version: '2.3.4.RELEASE'
      implementation group: 'org.springframework.boot', name: 'spring-boot-starter-actuator', version: '2.3.4.RELEASE'
      implementation group: 'org.springframework.boot', name: 'spring-boot-starter-jdbc', version: '2.3.4.RELEASE'
      implementation group: 'org.springframework.boot', name: 'spring-boot-starter-security', version: '2.3.4.RELEASE'
      implementation group: 'org.springframework.boot', name: 'spring-boot-starter-oauth2-resource-server', version: '2.3.4.RELEASE'
  
      implementation group: 'com.amazonaws', name: 'aws-java-sdk-secretsmanager', version: &quot;1.11.875&quot;
  
      implementation group: 'com.oracle.database.jdbc', name: 'ojdbc8', version: &quot;19.7.0.0&quot;
  
      implementation group: 'com.fasterxml.jackson.module', name: 'jackson-module-kotlin', version: '2.10.2'
  
      implementation group: 'org.springdoc', name: 'springdoc-openapi-kotlin', version: '1.4.3'
      implementation group: 'org.springdoc', name: 'springdoc-openapi-ui', version: '1.4.3'
  
      runtime group: 'com.h2database', name: 'h2', version: '1.4.194'
  
      testImplementation group: 'io.mockk', name: 'mockk', version: '1.9.3'
      testImplementation group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: '2.3.4.RELEASE'
      testImplementation group:'org.springframework.security', name: 'spring-security-test'
  }
  
  </code></pre>