title: Spring OAuth Server JBDCTokenStore Error
body: <p>I'm trying to add Database to Spring OAuth Server sample code.
  Here is the dataSource configuration.</p>
  
  <pre><code>@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;
  }
  </code></pre>
  
  <p>And EndpointConfig</p>
  
  <pre><code>    @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);
      }
  </code></pre>
  
  <p>But I get error on JbdctokenStore, JdbcClientDetailsService work fine.</p>
  
  <p>error message:</p>
  
  <blockquote>
    <p>Caused by: java.lang.IllegalArgumentException: DataSource required</p>
    
    <p>Caused by: org.springframework.beans.factory.BeanCreationException:
    Error creating bean with name 'tokenStore' defined in class path
    resource
    [org/springframework/security/oauth/examples/sparklr/config/OAuth2ServerConfig$AuthorizationServerConfiguration.class]:
    Instantiation of bean failed; nested exception is
    org.springframework.beans.factory.BeanDefinitionStoreException:
    Factory method [public
    org.springframework.security.oauth2.provider.token.TokenStore
    org.springframework.security.oauth.examples.sparklr.config.OAuth2ServerConfig$AuthorizationServerConfiguration.tokenStore()]
    threw exception; nested exception is
    java.lang.IllegalArgumentException: DataSource required</p>
  </blockquote>
  
  <p>I couldn't figure out what happen.
  Database and Table is all fine.(I use the sql file the sample gave.)</p>
  
  <hr>
  
  <pre><code>        @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;
      }
  </code></pre>
  
  <p>I just add a new bean under it and change dataSource to dataSource(),
  and it work.
  I can't get it, why JdbcClientDetailsService work with orignal one.
  But JdbcTokenStore need a new one.
  How can I change this part of code, the code looks messy because of duplicate code.</p>