Spring Boot 出现java.lang.NoClassDefFoundError: org/apache/tomcat/util/security/Escape错误

Spring Boot整合Jsp的过程中,编译报出如下错误。

2018-03-15 22:04:45.166 ERROR 7240 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [java.lang.NoClassDefFoundError: org/apache/tomcat/util/security/Escape] with root cause

java.lang.ClassNotFoundException: org.apache.tomcat.util.security.Escape
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381) ~[na:1.8.0_111]
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_111]
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) ~[na:1.8.0_111]
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_111]
    at org.apache.jasper.compiler.JspUtil.getExprInXml(JspUtil.java:85) ~[tomcat-embed-jasper-9.0.6.jar:9.0.6]
    at org.apache.jasper.compiler.PageDataImpl$SecondPassVisitor.printAttributes(PageDataImpl.java:736) ~[tomcat-embed-jasper-9.0.6.jar:9.0.6]
    at org.apache.jasper.compiler.PageDataImpl$SecondPassVisitor.appendTag(PageDataImpl.java:470) ~[tomcat-embed-jasper-9.0.6.jar:9.0.6]
    at org.apache.jasper.compiler.PageDataImpl$SecondPassVisitor.appendTag(PageDataImpl.java:454) ~[tomcat-embed-jasper-9.0.6.jar:9.0.6]
    at org.apache.jasper.compiler.PageDataImpl$SecondPassVisitor.visit(PageDataImpl.java:266) ~[tomcat-embed-jasper-9.0.6.jar:9.0.6]
    at org.apache.jasper.compiler.Node$Root.accept(Node.java:470) ~[tomcat-embed-jasper-9.0.6.jar:9.0.6]
    at org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2389) ~[tomcat-embed-jasper-9.0.6.jar:9.0.6]
    at org.apache.jasper.compiler.PageDataImpl.(PageDataImpl.java:79) ~[tomcat-embed-jasper-9.0.6.jar:9.0.6]
    at org.apache.jasper.compiler.Validator.validateExDirectives(Validator.java:1862) ~[tomcat-embed-jasper-9.0.6.jar:9.0.6]
    at org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:224) ~[tomcat-embed-jasper-9.0.6.jar:9.0.6]
    at org.apache.jasper.compiler.Compiler.compile(Compiler.java:385) ~[tomcat-embed-jasper-9.0.6.jar:9.0.6]
    at org.apache.jasper.compiler.Compiler.compile(Compiler.java:362) ~[tomcat-embed-jasper-9.0.6.jar:9.0.6]
    at org.apache.jasper.compiler.Compiler.compile(Compiler.java:346) ~[tomcat-embed-jasper-9.0.6.jar:9.0.6]
    at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:603) ~[tomcat-embed-jasper-9.0.6.jar:9.0.6]
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369) ~[tomcat-embed-jasper-9.0.6.jar:9.0.6]
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:386) ~[tomcat-embed-jasper-9.0.6.jar:9.0.6]
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:330) ~[tomcat-embed-jasper-9.0.6.jar:9.0.6]

经检查发现,是由于tomcat-embed-jasper依赖只能设置为运行时依赖,将build.gradle文件依赖。

compile group: 'org.apache.tomcat.embed', name: 'tomcat-embed-jasper', version: '9.0.6'

修改为

runtime ("org.apache.tomcat.embed:tomcat-embed-jasper")

你可能感兴趣的:(Spring,Boot)