首页 > Spring interceptor中取不到@Value

Spring interceptor中取不到@Value

@Component
public class AuthorizeInterceptor extends HandlerInterceptorAdapter {

    private Logger log = Logger.getLogger(AuthorizeInterceptor.class);

    @Value("${usercenter.url.token}")
    private String tokenValidateUrl;

    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
       //这里tokenValidateUrl是null
        return true;
    }

是spring初始化顺序的问题吗?


什么版本的sping?


原因是这个AuthorizeInterceptor类实例是在初始化时手动new的,而不是交给spring来管理的,具体解决方案可以查看@Bean注解相关信息


我也遇到这个问题。什么原因呢?正查着。

【热门文章】
【热门文章】