Using jdbcAuthentication in Spring Security with Hibernate

后端 未结 1 1847
耶瑟儿~
耶瑟儿~ 2021-02-01 07:06

I just finished an Spring application which is based on the inMemoryAuthentication(), and now, after verified all are working perfectly, I want use the JDBC Authent

相关标签:
1条回答
  • 2021-02-01 07:55

    Ok, I solved it. All I needed to do was insert the following annotation in my class SecurityConfig:

    @ComponentScan(value="org.webapp")
    

    And now I can autowire my DataSource in this class

    @Autowired
    private DataSource restDataSource;
    
    @Autowired
    public void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth
            .jdbcAuthentication()
            .dataSource(restDataSource)
            .usersByUsernameQuery(getUserQuery())
            .authoritiesByUsernameQuery(getAuthoritiesQuery());
    }
    
    0 讨论(0)
提交回复
热议问题