[英]No bean named 'springSecurityFilterChain' is defined Java Config
i have class that should initialize filter chain by itself 我有应该自行初始化过滤器链的类
public class SecurityWebApplicationInitializer
extends AbstractSecurityWebApplicationInitializer {
}
but still i get noSuchBeanDefinException. 但我仍然得到noSuchBeanDefinException。
My webSecurityConfig 我的webSecurityConfig
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(securedEnabled=true)
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private UserService userService;
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(userService).passwordEncoder(passwordEncoder());
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().antMatchers("/admin/**")
.access("hasRole('ADMIN')").and().formLogin()
.loginPage("/login").failureUrl("/login?error")
.usernameParameter("username")
.passwordParameter("password")
.and().logout().logoutSuccessUrl("/login?logout")
.and().csrf()
.and().exceptionHandling().accessDeniedPage("/403");
}
@Bean
public PasswordEncoder passwordEncoder() {
PasswordEncoder encoder = new BCryptPasswordEncoder();
return encoder;
}
}
and here my AppInitialiser 这是我的AppInitialiser
public class WebAppInit extends AbstractAnnotationConfigDispatcherServletInitializer {
@Override
protected Class<?>[] getRootConfigClasses() {
return new Class[] { HibernateConfig.class};
}
@Override
protected Class<?>[] getServletConfigClasses() {
return new Class[] { WebMvcConfig.class};
}
@Override
protected String[] getServletMappings() {
return new String[]{"/"};
}
}
i tried to use WebSecurityConfig.class in AppInit but then it shows An error that my service class that autowired in SecurityConfig doesn't initialised when AppInit Class works. 我尝试在AppInit中使用WebSecurityConfig.class,但随后显示一个错误,当AppInit类工作时,在SecurityConfig中自动装配的服务类未初始化。 Also every single online example do like i do.
每个在线示例也都像我一样。 They just use SecurityWebApplicationInitializer .
他们只是使用SecurityWebApplicationInitializer。
First - put WebSecurityConfig into 首先-将WebSecurityConfig放入
@Override
protected Class<?>[] getRootConfigClasses() {
return new Class[] { HibernateConfig.class};
}
and also add @componentScan package FOR EVERY CONFIG class you have. 并为您拥有的每个CONFIG类添加@componentScan包。 My mistake was that i thought that they know about each other.
我的错误是我以为他们彼此了解。 Guess not.
可能不会。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.