[英]Login with Spring Security and jdbcTemplate
How to login with Spring Security using jdbcTemplate? 如何使用jdbcTemplate使用Spring Security登录?
@Bean
public JdbcTemplate jdbcTemplate(){
return new JdbcTemplate(dataSource());
}
^this is my JdbcTemplateBean ^这是我的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? 但是,我必须使用DataSource还是有办法使用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. 您可以使用@Value注释或Environment类从application.properties中获取字段。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.