0
我配置Spring安全注册豆,下面是我的代码 -春:通过私有方法
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(customUserDetailsService).passwordEncoder(encoder);
}
@Bean(name="encoder")
public BCryptPasswordEncoder getPasswordEncoder(){
return new BCryptPasswordEncoder();
}
@Override
protected void configure(HttpSecurity http) throws Exception {
...
}
只要我申请@Autowire导通
@Override
@Autowire
protected void configure(HttpSecurity http) throws Exception {
...
}
这引发异常无豆在容器中键入'HttpSecurity',这是预期的。
但是当我申请@Autowire
导通
@Override
@Autowire
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(customUserDetailsService).passwordEncoder(encoder);
}
有没有例外? 这个AuthenticationManagerBuilder
这个bean是在bean factory吗?
当我改变了我的豆登记私有方法像这个 -
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(customUserDetailsService).passwordEncoder(getPasswordEncoder());
}
@Bean(name="encoder")
private BCryptPasswordEncoder getPasswordEncoder(){
return new BCryptPasswordEncoder();
}
这是抛出异常,方法不能是private.Why这样呢?
标记为最终或私人你有两个问题。后者应该是不言自明的。首先,你使用Boot吗? – chrylis
@chrylis这是spring mvc项目,Iam不在这里使用spring boot。 – TheCurious