春季启动jsp:java.lang.NoClassDefFoundError:org/apache/tomcat/util/security/Escape

问题描述:

我试图在我的Spring Boot应用程序中添加一个简单的jsp渲染.

I am trying to add a simple jsp rendering in my spring boot application.

@Controller
public class WelcomeController {    
    @RequestMapping("/index")
    public String loginMessage(){
        return "index";
    }
}

解析器

spring.mvc.view.prefix=/WEB-INF/jsp/
spring.mvc.view.suffix=.jsp

和/src/main/webapp/WEB-INF/jsp/index.jsp

and /src/main/webapp/WEB-INF/jsp/index.jsp

我同时添加了sprng boot web stater和tomcat embed

I added both sprng boot web stater and tomcat embed

compile('org.springframework.boot:spring-boot-starter-web')
compile('org.apache.tomcat.embed:tomcat-embed-jasper')

我正面临这个问题

May 11, 2018 3:54:53 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: 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

我通过使用compileOnly解决了该问题

I fixed this by using compileOnly

compile('org.springframework.boot:spring-boot-starter-web')
compileOnly('org.apache.tomcat.embed:tomcat-embed-jasper')

仅编译类似于maven中提供的范围.

compile only is similar to scope provided in maven.