title: Change the database from H2 to MySQL for the Spring Boot + Spring Security?
body: <p>I developed <strong>Spring Boot OAuth2</strong> example which works fine with the <code>H2 DB</code>. Now the same I want to implement for the MySQL DB. What changes do I need to make in order to work with the MySQL DB ?</p>
  
  <p>I am very new to the Spring Security and boot, any help ?</p>
  
  <p><strong>H2Configuration.java</strong></p>
  
  <pre><code>@Configuration
  public class H2Configuration {
      @Bean
      public ServletRegistrationBean h2servletRegistration() {
          WebServlet webServlet = new WebServlet();
          ServletRegistrationBean bean = new ServletRegistrationBean(webServlet);
          bean.addUrlMappings("/h2console/*");
          return bean;
      }
  }
  </code></pre>
  
  <p><strong>SecurityConfiguration.java</strong></p>
  
  <pre><code>@Configuration
  @EnableWebSecurity
  public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
  
      @Autowired
      private UserDetailsService userDetailsService;
  
      @Bean
      public PasswordEncoder passwordEncoder() {
          return new StandardPasswordEncoder();
      }
  
      @Autowired
      public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
  
          auth
          .userDetailsService(userDetailsService)
          .passwordEncoder(passwordEncoder());
  
      }
  
      @Override
      public void configure(WebSecurity web) throws Exception {
  
          web
          .ignoring()
          .antMatchers("/h2console/**")
          .antMatchers("/api/register")
          .antMatchers("/api/activate")
          .antMatchers("/api/lostpassword")
          .antMatchers("/api/resetpassword")
          .antMatchers("/api/hello");
  
      }
  
      @Override
      @Bean
      public AuthenticationManager authenticationManagerBean() throws Exception {
          return super.authenticationManagerBean();
      }
  
      @EnableGlobalMethodSecurity(prePostEnabled = true, jsr250Enabled = true)
      private static class GlobalSecurityConfiguration extends GlobalMethodSecurityConfiguration {
          @Override
          protected MethodSecurityExpressionHandler createExpressionHandler() {
              return new OAuth2MethodSecurityExpressionHandler();
          }
  
      }
  }
  </code></pre>
  
  <p>application.properties:</p>
  
  <pre><code>#data source properties
  spring.datasource.url=jdbc:h2:mem:spring_boot_oauth2
  spring.datasource.username=
  spring.datasource.password=
  spring.datasource.dataSourceClassName=org.h2.jdbcx.JdbcDataSource
  spring.datasource.schema=classpath:/sql/schema.sql
  spring.datasource.data=classpath:/sql/data.sql
  #spring.datasource.driverClassName=com.mysql.jdbc.Driver
  
  # JPA properties
  spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
  spring.jpa.database=H2
  spring.jpa.openInView=false
  spring.jpa.show_sql=true
  spring.jpa.generate-ddl=false
  spring.jpa.hibernate.ddl-auto=none
  
  #web server
  server.port=9191
  server.contextPath=/api
  
  #Application specific
  authentication.oauth.clientid=rajithapp
  authentication.oauth.secret=secret
  authentication.oauth.tokenValidityInSeconds=1800
  </code></pre>