@Autowired 成员变量,使用时为null

277 阅读1分钟

起因

image.png image.png

UserAuthenticationFilter 中需要引入 Service

问题

  • UserAuthenticationFilter 的 构造方法需要一个 AuthenticationManager 实例,因此简单加上 @Component 注解无效

  • 考虑使用 @Configure + @Bean 的方式 交由Spring 管理

  • @Bean 、@Autowired 不能同时使用

解决办法

image.png