欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2024-02-11 20:52:22
开发环境使用jdk1.8.0_60,把springboot 项目打成war包后, 部署到apache-tomcat-7.0.68时报错如下,换成apache-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

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

以上所述是小编给大家介绍的springboot项目打成war包部署到tomcat遇到的一些问题,希望对大家有所帮助