Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Heroku deployment error "required a bean of type 'org.springframework.security.oauth2.jwt.JwtDecoder' that could not be found."

I am trying to deploy my springboot app to heroku but I am getting an error that it cannot find a JwtDecoder bean. I have tried googling it a bit but can't find anything that helps. Everything works fine locally, just not when deployed to heroku.

Here is my heroku log --tail:

2021-02-27T20:18:45.134160+00:00 app[web.1]: ***************************
2021-02-27T20:18:45.134160+00:00 app[web.1]: APPLICATION FAILED TO START
2021-02-27T20:18:45.134160+00:00 app[web.1]: ***************************
2021-02-27T20:18:45.134161+00:00 app[web.1]:
2021-02-27T20:18:45.134161+00:00 app[web.1]: Description:
2021-02-27T20:18:45.134161+00:00 app[web.1]:
2021-02-27T20:18:45.134179+00:00 app[web.1]: Method springSecurityFilterChain in
org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration 
required a bean of type 'org.springframework.security.oauth2.jwt.JwtDecoder' that 
could not be found.
2021-02-27T20:18:45.134179+00:00 app[web.1]: 
2021-02-27T20:18:45.134179+00:00 app[web.1]:
2021-02-27T20:18:45.134180+00:00 app[web.1]: Action:
2021-02-27T20:18:45.134180+00:00 app[web.1]:
2021-02-27T20:18:45.134181+00:00 app[web.1]: Consider defining a bean of type 
'org.springframework.security.oauth2.jwt.JwtDecoder' in your configuration.

WebSecurityConfig:

@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception{
        http.csrf().disable().cors().configurationSource(corsConfigurationSource())
                .and()
                .authorizeRequests()
                .antMatchers("/*")
                .authenticated()
                .and()
                .oauth2ResourceServer()
                .jwt();
    }

I'm not sure what else to include... Feel free to comment on what else I should add. Or, the repo is at https://github.com/AndreTheTallGuy/Kelp2

Thank you in advance for any help you may be able to provide!

like image 731
AndreTheTallGuy Avatar asked Sep 16 '25 15:09

AndreTheTallGuy


1 Answers

Try to specify the jwk-set-uri configuration in application.yml:

spring:
  security:
    oauth2:
      resourceserver:
        jwt:
          jwk-set-uri: https://example.com/.well-known/jwks.json

For application.properties:

spring.security.oauth2.resourceserver.jwt.jwk-set-uri=https://example.com/.well-known/jwks.json
like image 58
Iceberg Avatar answered Sep 19 '25 04:09

Iceberg