【问题标题】:Spring Boot Ignoring Configuration Bean, Or Building in Wrong Order?Spring Boot 忽略配置 Bean,还是构建顺序错误?
【发布时间】:2018-12-20 01:04:47
【问题描述】:

我有一个具有相当标准配置和安全配置的 JHipster 5.3.4 项目,但是在尝试运行该项目时,我收到以下错误,表示缺少 bean。

root/config/SecurityConfiguration.java 我有以下类头和内部 bean

@Configuration
@Import(SecurityProblemSupport.class)
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true)
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {

...

    @Override
    @Bean
    public AuthenticationManager authenticationManagerBean() throws Exception {
        return super.authenticationManagerBean();
    }
...
}

root/web/rest/UserJWTController.java 我有以下内容

@RestController
@RequestMapping("/api")
public class UserJWTController {
   private final TokenProvider tokenProvider;
   private final AuthenticationManager authenticationManager;

   public UserJWTController(TokenProvider tokenProvider, 
                            AuthenticationManager  authenticationManager) {
       this.tokenProvider = tokenProvider;
       this.authenticationManager = authenticationManager;
   }
...

但是当我尝试运行该项目时,我得到: au.com.suncorp.pp.web.rest.UserJWTController 中构造函数的参数 1 需要 'org.springframework.security.authentication.AuthenticationManager' 类型的 bean

我假设有一个 bean 构建排序问题,但我没有我的元素。有人可以帮忙吗?

【问题讨论】:

  • 移除 authenticationManagerBean()
  • 为什么?这是应用程序中任何位置的 AuthenticationManager 的唯一构造函数。它还会去哪里?
  • 提问之前,有没有试过把它去掉,看看有没有错误?
  • 与以前完全相同的错误。
  • UserJWTController 中需要 AuthenticationManager 的确切代码是什么?

标签: java spring spring-boot jhipster


【解决方案1】:

所以 UserJWTController 是你的类,对吧?

你为什么不自动接线?

@Autowired
@Qualifier("authenticationManagerBean")
public AuthenticationManager authenticationManager;

【讨论】:

猜你喜欢
  • 2014-07-20
  • 2019-12-25
  • 2016-07-05
  • 2018-06-21
  • 1970-01-01
  • 2019-09-28
  • 2019-04-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多