How to login with Spring Security using jdbcTemplate?
@Bean
public JdbcTemplate jdbcTemplate(){
return new JdbcTemplate(dataSource());
}
^this is my JdbcTemplateBean
@Autowired
JdbcTemplate jdbcTemplate;
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception{
auth
.jdbcAuthentication()
.dataSource(jdbcTemplate)
this code gives me this error:
dataSource(javax.sql.DataSource) in JdbcUserDetailsManagerConfigurer cannot be applied to (org.springframework.jdbc.core.JdbcTemplate)
when I'm using data source its working
@Autowired
DataSource dataSource;
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception{
auth
.jdbcAuthentication()
.dataSource(dataSource)
But do I have to use DataSource or maybe there is a way to use JdbcTemplate?
Create config class, which will have method, which returns datasource. Fields from your application.properties you can get with @Value annotation or with Environment class.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.