【问题标题】:@Bean method with arguments带参数的@Bean 方法
【发布时间】:2015-11-12 21:05:24
【问题描述】:

我在设置带有 @Bean 注释方法的 bean 时遇到了一些问题。 Spring 版本是 4.1.4。

抛出的错误是:

org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'authenticationManagerBuilder' defined in class org.springframework.security.config.annotation.authentication.configuration.AuthenticationConfiguration: Can only specify arguments for the getBean method when referring to a prototype bean definition

起初我以为它只是在我的代码中,但后来我删除了它并开始出现在 Spring 托管的 bean 中,例如 AuthenticationConfiguration。

我在其他项目中使用相同的,它正在工作,所以我认为这个配置有问题。

我发现了一个指向 spring 版本 4.1.3 的问题,但它似乎已在下一个版本中修复,所以我不知道可能会发生什么。 https://jira.spring.io/browse/SPR-12488

我再次使用这种策略很长时间了,例如:

@Bean
public DelegatingTokenGranter delegatingTokenGranter(AuthorizationServerEndpointsConfigurer endpoints) {
    return new DelegatingTokenGranter(endpoints);
}

然后在配置中调用类似:

@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
    endpoints
            .tokenStore(tokenStore())
            .authenticationManager(authenticationManager)
            .addInterceptor(oAuth2ThreadContextInterceptor())
            .tokenGranter(delegatingTokenGranter(endpoints));
}

有什么想法吗?

【问题讨论】:

    标签: spring spring-security spring-security-oauth2


    【解决方案1】:

    好吧,原来 spring-oauth2 从 4.0.8 版本的 spring 中提取了一些模块。我修复了这些并手动强制当前版本,现在一切似乎都正常了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-01-27
      • 2013-09-29
      • 2015-07-29
      • 2013-04-24
      • 2012-12-29
      • 2013-09-29
      • 1970-01-01
      • 2016-08-09
      相关资源
      最近更新 更多