spring-boot报错 ERROR 5564

2019-02-13 21:05:26.376 ERROR 5564 --- [nio-8080-exec-2] o.a.c.c.C.[.[.[.[dispatcherServlet]      : Servlet.service() for servlet [dispatcherServlet] threw exception

java.lang.NullPointerException: null

造成的原因是因为我自己定义了LocaleResolver到容器中,但是由于我在重写的时候粗心了没有给默认的Locale

 @Override
    public Locale resolveLocale(HttpServletRequest httpServletRequest) {
        String l=httpServletRequest.getParameter("l");
//        Locale locale=Locale.getDefault();
        Locale locale=null;
        if (!StringUtils.isEmpty(l)){
            String[] split = l.split("_");
             locale = new Locale(split[0], split[1]);
        }
        return locale;
    }

解决方法:在为空的时候给一个默认的Locale.getDefault();即可

 @Override
    public Locale resolveLocale(HttpServletRequest httpServletRequest) {
        String l=httpServletRequest.getParameter("l");
        Locale locale=Locale.getDefault();
        if (!StringUtils.isEmpty(l)){
            String[] split = l.split("_");
             locale = new Locale(split[0], split[1]);
        }
        return locale;
    }

猜你喜欢

转载自blog.csdn.net/yjt520557/article/details/87207767