spring boot 拦截器 注入dao 操作数据库时dao 为null

来源:互联网 发布:网络大电影 编辑:程序博客网 时间:2024/06/03 16:29

再做spring boot demo 项目时 想通过拦截器 拦截登录请求时的cookie 用cookie中携带的用户信息查询数据库实现下次自动登录功能,

但是在拦截器 中注入了dao 获取时发现为null,最后通过这样方式实现

之前是通过自己手动new 出来的LoginInterceptor 放到registry 中,这样自己手动new出来的bean spring是不能自动注入进来的,需要通过@bean 让spring 来帮助我们为LoginInterceptor 注入我们需要的bean


参考:https://stackoverflow.com/questions/23349180/java-config-for-spring-interceptor-where-interceptor-is-using-autowired-spring-b


原创粉丝点击