gpt4 book ai didi

stack-overflow - Spring oauth2中的StackOverflowError与自定义ClientDetailsS​​ervice

转载 作者:行者123 更新时间:2023-12-04 00:49:42 25 4
gpt4 key购买 nike

我自己实现了ClientDetailsS​​ervice:

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

ClientRepository 是一个标准的 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).
我不明白为什么。

最佳答案

我不明白为什么,但如果我直接注入(inject)我的 bean 而不是注入(inject)接口(interface),它可以工作:

public class OAuth2ServerConfig extends AuthorizationServerConfigurerAdapter {
...
@Autowired
private JpaClientDetailsService clientDetailsService;
...

如果我使用 @Primary 注释来注释我的服务,它也可以工作:
@Service
@Primary
public class JpaClientDetailsService implements ClientDetailsService {

关于stack-overflow - Spring oauth2中的StackOverflowError与自定义ClientDetailsS​​ervice,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31798631/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com