本文介绍了带有自定义ClientDetailsService的Spring OAuth2中的StackOverflow Error的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我自己实现了ClientDetailsService:
@Service
public class JpaClientDetailsService implements ClientDetailsService {
@Autowired
private ClientRepository clientRepositoy;
@Override
public ClientDetails loadClientByClientId(String clientId) throws ClientRegistrationException {
ClientDetails client = clientRepositoy.findOne(clientId);
if (client == null) {
throw new ClientRegistrationException(String.format("Client with id %s not found", clientId));
}
return client;
}
}
客户端存储库是标准JpaRepository。
我配置了AuthorizationServerConfigurerAdapter,如下所示:
@Configuration
@EnableAuthorizationServer
@EnableResourceServer
public class OAuth2ServerConfig extends AuthorizationServerConfigurerAdapter {
@Autowired
private AuthenticationManager authenticationManager;
@Autowired
private ClientDetailsService clientDetailsService;
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
endpoints.authenticationManager(authenticationManager);
}
@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
clients.withClientDetails(clientDetailsService);
}
}
但当我转到http://localhost:9999/oauth/authorize?response_type=code&client_id=lipton
时,我收到一个
java.lang.StackOverflowError: null. Spring loops on com.sun.proxy.$Proxy81.loadClientByClientId(Unknown Source).
我不明白为什么。
推荐答案
我不知道为什么,但如果我直接注入我的Bean,而不是注入接口,它可以工作:
public class OAuth2ServerConfig extends AuthorizationServerConfigurerAdapter {
...
@Autowired
private JpaClientDetailsService clientDetailsService;
...
如果我用@Primary批注来批注我的服务,它也会起作用:
@Service
@Primary
public class JpaClientDetailsService implements ClientDetailsService {
这篇关于带有自定义ClientDetailsService的Spring OAuth2中的StackOverflow Error的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!