@Bean 带参数的方法
@Bean method with arguments
我在使用 @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-oauth2 正在从 spring 中提取一些模块,形成 4.0.8 版本。我修复了这些问题并手动强制使用当前版本,现在似乎一切正常。
我在使用 @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-oauth2 正在从 spring 中提取一些模块,形成 4.0.8 版本。我修复了这些问题并手动强制使用当前版本,现在似乎一切正常。