Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

在sprinb-boot的interceptor中用 @Reference注入dubbo服务,但是为空。 #340

Open
cy503328434 opened this issue Jan 3, 2018 · 1 comment

Comments

@cy503328434
Copy link

cy503328434 commented Jan 3, 2018

public class CustomInterceptor implements HandlerInterceptor {
@reference(version = "1.0.0")
private SessionProvider sessionProvider;

@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
        throws Exception {
    log.info("CustomInterceptor preHandle start.");
    //用户必须登录 
    String uername = sessionProvider.getAttributeForUser(RequestUtil.getCSESSIONID(request, response));
    //未登录
    if (StringUtils.isBlank(uername)) {
        return false;
    }
    log.info("CustomInterceptor preHandle end.");
    return true;
}

@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
                       ModelAndView modelAndView)
        throws Exception {
    log.info("CustomInterceptor postHandle.");
}

@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
        throws Exception {
    log.info("CustomInterceptor afterCompletion.");
}

}

@ExpoBailey
Copy link

应该是消费者的扫描包没有扫到这个拦截器的目录,而且拦截器不能手动new喔:
spring.dubbo.scan=要包括这个拦截器的包

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants