簡體   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