Heroku 部署错误“需要一个无法找到的‘org.springframework.security.oauth2.jwt.JwtDecoder’类型的 bean。”

时间:2021-02-27 20:36:04

标签: java spring-boot heroku jwt

我正在尝试将我的 springboot 应用程序部署到 heroku,但我收到一个错误,说它找不到 JwtDecoder bean。我试过用谷歌搜索一下,但找不到任何有用的东西。在本地一切正常,只是在部署到 heroku 时不行。

这是我的 Heroku 日志 --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.

网络安全配置:

@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();
    }

我不确定还需要添加什么...请随意评论我应该添加的其他内容。或者,回购位于 https://github.com/AndreTheTallGuy/Kelp2

预先感谢您提供的任何帮助!

1 个答案:

答案 0 :(得分:0)

它找不到 org.springframework.security.oauth2.jwt.JwtDecoder,因为您将该依赖项列为 test scope

    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-test</artifactId>
        <scope>test</scope>
    </dependency>

enter image description here

更改 scope 或删除该条目。默认条目为 compile