我試圖將數據庫添加到Spring OAuth Server示例代碼。 以下是dataSource配置。Spring OAuth服務器JBDCTokenStore錯誤
@Bean(name = "dataSource")
public DriverManagerDataSource dataSource() {
DriverManagerDataSource driverManagerDataSource = new DriverManagerDataSource();
driverManagerDataSource.setDriverClassName("org.mariadb.jdbc.Driver");
driverManagerDataSource.setUrl("jdbc:mariadb://localhost:3306/OAuth");
driverManagerDataSource.setUsername("root");
driverManagerDataSource.setPassword("password");
return driverManagerDataSource;
}
而且EndpointConfig
@Autowired
private DataSource dataSource;
@Bean
public JdbcClientDetailsService clientDetailsService() {
return new JdbcClientDetailsService(dataSource);
}
@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
clients.withClientDetails(clientDetailsService());
}
@Bean
public TokenStore tokenStore() {
//return new InMemoryTokenStore();
return new JdbcTokenStore(dataSource);
}
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
endpoints.tokenStore(tokenStore);
endpoints.userApprovalHandler(userApprovalHandler);
endpoints.authenticationManager(authenticationManager);
}
但我得到JbdctokenStore,JdbcClientDetailsService做工精細錯誤。
錯誤消息:java.lang.IllegalArgumentException異常:
所致的DataSource需要
所致:org.springframework.beans.factory.BeanCreationException: 錯誤與名稱創建豆 'tokenStore'在類路徑中定義 資源 [org/springframework/security/oauth/examples/sparklr/config/OAuth2ServerConfig $ AuthorizationServerConfiguration.class]: bean的實例化失敗;嵌套的例外是 org.springframework.beans.factory.BeanDefinitionStoreException: 工廠方法[公共 org.springframework.security.oauth2.provider.token.TokenStore org.springframework.security.oauth.examples.sparklr.config.OAuth2ServerConfig $ AuthorizationServerConfiguration.tokenStore()] 引發異常;嵌套的例外是 java.lang.IllegalArgumentException異常:數據源需要
我無法弄清楚發生什麼。 數據庫和表是所有罰款。(我用的是SQL文件樣本給了。)
@Bean
public TokenStore tokenStore() {
//return new InMemoryTokenStore();
return new JdbcTokenStore(dataSource());
}
@Bean
public DriverManagerDataSource dataSource() {
DriverManagerDataSource driverManagerDataSource = new DriverManagerDataSource();
driverManagerDataSource.setDriverClassName("org.mariadb.jdbc.Driver");
driverManagerDataSource.setUrl("jdbc:mariadb://localhost:3306/OAuth");
driverManagerDataSource.setUsername("root");
driverManagerDataSource.setPassword("a89019");
return driverManagerDataSource;
}
我剛下它和改變數據源添加新豆到數據源(), 和它的工作。 我無法得到它,爲什麼JdbcClientDetailsService與orignal一起工作。 但JdbcTokenStore需要一個新的。 如何更改這部分代碼,代碼由於代碼重複而顯得雜亂無章。
您是否在'JdbcTokenStore'類上有'@ Configuration'註釋? – harshavmb
不,但我通過在其下添加重複代碼來解決錯誤。我不知道它爲什麼起作用。 –