What You'll Learn

@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
    
    ... 
    
    @Autowired
    private DataSource dataSource;
    
    ...
@Autowired
public void configureGlobal(final AuthenticationManagerBuilder auth) throws Exception {
    
    auth.jdbcAuthentication()
                .dataSource(dataSource);

}
create table users(
    username varchar_ignorecase(50) not null primary key,
    password varchar_ignorecase(500) not null,
    enabled boolean not null
);

create table authorities (
    username varchar_ignorecase(50) not null,
    authority varchar_ignorecase(50) not null,
    constraint fk_authorities_users foreign key(username) references users(username)
);
create unique index ix_auth_username on authorities (username,authority);
@Autowired
public void configureGlobal(final AuthenticationManagerBuilder auth) throws Exception {
    
    auth.jdbcAuthentication()
                .dataSource(dataSource)
                .usersByUsernameQuery("select username, password, enabled from User where username = ?")
                .authoritiesByUsernameQuery("select username, roles from user_roles where username = ?");

}