当前位置: 首页 > 编程笔记 >

springboot项目打成war包部署到tomcat遇到的一些问题

姬朗
2023-03-14
本文向大家介绍springboot项目打成war包部署到tomcat遇到的一些问题,包括了springboot项目打成war包部署到tomcat遇到的一些问题的使用技巧和注意事项,需要的朋友参考一下

开发环境使用jdk1.8.0_60,把springboot 项目打成war包后,

部署到apache-tomcat-7.0.68时报错如下,换成apache-tomcat-8.0.9解决

org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/my-springboot-web-0.0.1]]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:153)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:899)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:875)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:652)
    at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:1091)
    at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1980)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NoSuchMethodError: javax.servlet.ServletContext.getVirtualServerName()Ljava/lang/String;
    at org.apache.tomcat.websocket.server.WsServerContainer.<init>(WsServerContainer.java:149)
    at org.apache.tomcat.websocket.server.WsSci.init(WsSci.java:131)
    at org.apache.tomcat.websocket.server.WsSci.onStartup(WsSci.java:47)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5573)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
    ... 10 more
六月 22, 2017 12:19:15 上午 org.apache.catalina.startup.HostConfig deployWAR
严重: Error deploying web application archive E:\Data\apache-tomcat-7.0.68\webapps\my-springboot-web-0.0.1.war
java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/my-springboot-web-0.0.1]]
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:903)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:875)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:652)
    at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:1091)
    at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1980)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)

另外springboot项目打成war包部署到tomcat时需要改变启动方式,否则运行tomcat时war包只会解压,但是加载不了

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.web.SpringBootServletInitializer;
@SpringBootApplication  //- springboot项目,并配置扫描路径
@EnableAutoConfiguration //- springboot自动配置,这个注解可以根据你依赖的包自动生成相关配置
public class StartApp extends SpringBootServletInitializer {
  public static void main(String[] args) {
    SpringApplication.run(StartApp.class, args);
  }
  /**
   * 需要把web项目打成war包部署到外部tomcat运行时需要改变启动方式
   */
  @Override
  protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
    return builder.sources(StartApp.class);
  }

部署到外部tomcat时,注意pom.xml配置,否则会报错

<!-- 这里指定打war包的时不再需要tomcat相关的包,但是本地运行时必须注释掉,否则会报错 -->
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-tomcat</artifactId>
      <version>1.3.5.RELEASE</version>
      <scope>provided</scope>
    </dependency>
**报错信息:**
org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is java.lang.NoClassDefFoundError: org/apache/juli/logging/LogFactory
  at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:133)
  at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532)
  at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118)
  at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:766)
  at org.springframework.boot.SpringApplication.createAndRefreshContext(SpringApplication.java:361)
  at org.springframework.boot.SpringApplication.run(SpringApplication.java:307)
  at org.springframework.boot.SpringApplication.run(SpringApplication.java:1191)
  at org.springframework.boot.SpringApplication.run(SpringApplication.java:1180)
  at com.StartApp.main(StartApp.java:13)
Caused by: java.lang.NoClassDefFoundError: org/apache/juli/logging/LogFactory
  at org.apache.catalina.util.LifecycleBase.<clinit>(LifecycleBase.java:37)
  at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.getEmbeddedServletContainer(TomcatEmbeddedServletContainerFactory.java:158)
  at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:160)
  at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:130)
  ... 8 more
Caused by: java.lang.ClassNotFoundException: org.apache.juli.logging.LogFactory
  at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
  at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
  at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
  at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
  ... 12 more

springboot项目使用jsp页面时会添加以下依赖,但是在外部tomcat运行时会报错

因为tomcat /lib下自带的jar包(jasper.jar,jsp-api.jar等)会跟war包项目路径/lib下的解析jsp的jar包冲突

删除项目路径/lib下的相关jar包即可,如下图

<!-- 添加jsp支持 -->
    <dependency>
      <groupId>org.apache.tomcat.embed</groupId>
      <artifactId>tomcat-embed-jasper</artifactId>
      <version>8.0.33</version>
    </dependency>
**报错信息:**
[ERROR][2017-06-22 00:48:28,303][org.springframework.boot.context.web.ErrorPageFilter]Forwarding to error page from request [/excel] due to exception [java.lang.LinkageError: loader constraint violation: when resolving method "org.apache.jasper.runtime.InstanceManagerFactory.getInstanceManager(Ljavax/servlet/ServletConfig;)Lorg/apache/tomcat/InstanceManager;" the class loader (instance of org/apache/jasper/servlet/JasperLoader) of the current class, org/apache/jsp/jsp/excel_jsp, and the class loader (instance of java/net/URLClassLoader) for the method's defining class, org/apache/jasper/runtime/InstanceManagerFactory, have different Class objects for the type org/apache/tomcat/InstanceManager used in the signature]
javax.servlet.ServletException: java.lang.LinkageError: loader constraint violation: when resolving method "org.apache.jasper.runtime.InstanceManagerFactory.getInstanceManager(Ljavax/servlet/ServletConfig;)Lorg/apache/tomcat/InstanceManager;" the class loader (instance of org/apache/jasper/servlet/JasperLoader) of the current class, org/apache/jsp/jsp/excel_jsp, and the class loader (instance of java/net/URLClassLoader) for the method's defining class, org/apache/jasper/runtime/InstanceManagerFactory, have different Class objects for the type org/apache/tomcat/InstanceManager used in the signature

默认配置下就可以通过http://localhost:8080/war包名/@RequestMapping.value访问了, 另外部署到tomcat后静态资源(resources下的js文件)访问不到的问题还没解决。。。

以上所述是小编给大家介绍的springboot项目打成war包部署到tomcat遇到的一些问题,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对小牛知识库网站的支持!

 类似资料:
  • springboot 3 如何将 application.properties 打包在 war 包之外,并部署到 tomcat 中 在 开发环境中,把 application.properties 放到项目根目录的 config 目录下,打包的时候确实不带 application.properties 了, 但部署到 tomcat 时, application.properties 应该怎么弄

  • 问题内容: 我想将Spring Boot应用程序部署到Tomcat,因为我想部署到AWS。我创建了一个WAR文件,但是即使它可见,它似乎也不能在Tomcat上运行。 详细信息: 0。这是我的应用程序: 具有以下内容: 阅读了许多页面和问题后,我在POM中添加了以下内容: http://maven.apache.org/xsd/maven-4.0.0.xsd“> 4.0.0 我运行了“ mvn软件包

  • > 在阅读了大量页面和问答后,我在POM中添加了以下内容: http://maven.apache.org/xsd/maven-4.0.0.xsd“>4.0.0 我运行了“MVN包”,得到了WAR文件(大小250MB),我把它放进了“webapps”文件夹。

  • 有一个springboot项目想部署到阿里云上,需要简化部署流程,需要咨询几个问题: 1.生产上使用docker容器部署还是直接手动安装jdk,打jar包上传服务器? 2.使用宝塔部署安全可靠吗,是否可以简化部署,没使用过宝塔? 3.项目用到了MySQL和Redis,单独购买云数据库还是在运行springboot的服务器里自己安装MySQL和Redis服务? 4.项目是前后端分离的,是要单独再购买

  • 我正在使用spring boot,我想将一个rest API war文件部署到tomcat服务器中。tomcat服务器日志中没有错误,但当我调用任何endpoint时,我得到的是404“not found”,而我从tomcat服务器得到的是相同的。 java版本:8。tomcat版本:9。 也许我错过了什么,下面是我的代码示例: Pom: 2.application.java