【发布时间】:2016-12-24 21:02:53
【问题描述】:
如果我在 gradle 构建文件中将“spring-boot-starter-tomcat”插件依赖项设置为 compile,在部署到独立 Tomcat 7 服务器时会收到以下错误消息:
INFO: validateJarFile(/usr/share/tomcat/webapps/ROOT/WEB-INF/lib/tomcat-embed-core-8.0.36.jar) - jar not loaded. See Servlet Spec 3.0, section 10.7.2. Offending class: javax/servlet/Servlet.class
Aug 18, 2016 2:51:19 AM org.apache.catalina.loader.WebappClassLoader validateJarFile
INFO: validateJarFile(/usr/share/tomcat/webapps/ROOT/WEB-INF/lib/tomcat-embed-el-8.0.36.jar) - jar not loaded. See Servlet Spec 3.0, section 10.7.2. Offending class: javax/el/Expression.class
如果我将依赖项更改为 provided,我可以部署到 Tomcat,但尝试在 IntelliJ IDEA 15 中运行或调试时会出现以下错误:
ERROR org.springframework.boot.SpringApplication - Application startup failed
org.springframework.beans.factory.BeanDefinitionStoreException: Failed to process import candidates for configuration class [orderserver.Application]; nested exception is java.lang.IllegalStateException: Failed to introspect annotated methods on class org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport
...
Caused by: java.lang.IllegalStateException: Failed to introspect annotated methods on class org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport
...
Caused by: java.lang.NoClassDefFoundError: javax/servlet/ServletContext
...
Caused by: java.lang.ClassNotFoundException: javax.servlet.ServletContext
如何在生成 war 文件时排除这些依赖项,同时保留在 IDEA 中运行/调试的能力?
有没有一种方法可以生成一个嵌入了 Tomcat 的单一 war 文件,用于独立执行,也可以部署到 Tomcat 容器中?
【问题讨论】:
-
我们在 grailsVersion=3.1.4 项目中使用
provided,它在 IDE 中运行流畅(IntelliJ IDEA 2016.1.3 Build #IU-145.1617,于 6 月 3 日构建, 2016) 或生产 Tomcat。确定不是tomcat版本不匹配的问题? -
@Michal_Szulc 是的,这是 tomcat 版本的问题,因为我在生产中部署到 Tomcat 7,但是当我将依赖项更改为“提供”时,我无法再在 IDEA 中运行。
标签: grails gradle spring-boot