繁体   English   中英

使用Spring Security和jdbcTemplate登录

[英]Login with Spring Security and jdbcTemplate

如何使用jdbcTemplate使用Spring Security登录?

@Bean
public JdbcTemplate jdbcTemplate(){
    return new JdbcTemplate(dataSource());
}

^这是我的JdbcTemplateBean

@Autowired
JdbcTemplate jdbcTemplate;
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception{
    auth
            .jdbcAuthentication()
            .dataSource(jdbcTemplate)

此代码给我这个错误:

dataSource(javax.sql.DataSource) in JdbcUserDetailsManagerConfigurer cannot be applied to (org.springframework.jdbc.core.JdbcTemplate)

当我使用数据源时

@Autowired
DataSource dataSource;

@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception{
    auth
            .jdbcAuthentication()
            .dataSource(dataSource)

但是,我必须使用DataSource还是有办法使用JdbcTemplate?

创建配置类,该类将具有方法,该方法返回数据源。 您可以使用@Value注释或Environment类从application.properties中获取字段。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM