springboot (备忘录) 2.4.6 升级 2.5.1

2021-07-01  本文已影响0人  逮到兔子的狐狸

记录一个错误
Error creating bean with name 'springSecurityFilterChain' defined in class path resource [org/springframework/security/config/annotation/web/configuration/WebSecurityConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.servlet.Filter]: Factory method 'springSecurityFilterChain' threw exception; nested exception is java.lang.NullPointerException

/**
 * spring security配置

 */
public class SecurityConfig extends WebSecurityConfigurerAdapter{
...

   @Override
    protected void configure(HttpSecurity httpSecurity) throws Exception {
     ....

        // 添加JWT filter
        httpSecurity.addFilterBefore(jwtAuthenticationTokenFilter,   
       UsernamePasswordAuthenticationFilter.class);

        // 添加CORS filter

        httpSecurity.addFilterBefore(corsFilter, LogoutFilter.class);
//        这一行不注释掉会报错, 查了一下,好像是因为  corsFilter的顺序本来就高。。。
//       corsFilter,JwtAuthenticationTokenFilter  都是继承  OncePerRequestFilter
//      httpSecurity.addFilterBefore(corsFilter, JwtAuthenticationTokenFilter.class);
    }

...
}
上一篇下一篇

猜你喜欢

热点阅读