The*_*ous 2 java spring spring-mvc
我正在配置 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 {
...
}
Run Code Online (Sandbox Code Playgroud)
一旦我应用了@Autowire-
@Override
@Autowire
protected void configure(HttpSecurity http) throws Exception {
...
}
Run Code Online (Sandbox Code Playgroud)
这会在容器中引发异常,没有类型为“HttpSecurity”的 bean,这是预期的。
但是当我申请时@Autowire——
@Override
@Autowire
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(customUserDetailsService).passwordEncoder(encoder);
}
Run Code Online (Sandbox Code Playgroud)
没有例外?这个AuthenticationManagerBuilder豆子在豆厂里怎么样?
当我用这样的私有方法更改我的 bean 注册时 -
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(customUserDetailsService).passwordEncoder(getPasswordEncoder());
}
@Bean(name="encoder")
private BCryptPasswordEncoder getPasswordEncoder(){
return new BCryptPasswordEncoder();
}
Run Code Online (Sandbox Code Playgroud)
这是抛出异常,方法不能是私有的。为什么会这样?
| 归档时间: |
|
| 查看次数: |
5214 次 |
| 最近记录: |