大家好,我是烤鸭:

关于springboot war包部署tomcat。

环境:

springboot 2.0.3.RELEASE

apache-tomcat-8.5.32

1.    修改pom

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns="http://maven.apache.org/POM/4.0.0"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.0.3.RELEASE</version></parent><groupId>com.xxx.xxx</groupId><version>1.0.0-SNAPSHOT</version><artifactId>xxx_xxxx_interface</artifactId><packaging>war</packaging><name>xxx_xxxx_interface</name><description>xxx接口</description><properties><maven.compiler.source>1.8</maven.compiler.source><maven.compiler.target>1.8</maven.compiler.target><maven.compiler.encoding>UTF-8</maven.compiler.encoding><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><project.build.locales>zh_CN</project.build.locales></properties><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency></dependencies><profiles><profile><!--本地开发环境 --><id>dev</id><properties><profiles.active>dev</profiles.active></properties><activation><activeByDefault>true</activeByDefault></activation></profile><profile><!--测试环境 --><id>test</id><properties><profiles.active>test</profiles.active></properties></profile><profile><!--生产环境 --><id>pro</id><properties><profiles.active>pro</profiles.active></properties></profile></profiles><build><finalName>xxxx_interface</finalName> <!-- 指定package生成的文件名为my-spring-boot.jar --><resources><!-- 所有环境配置文件过滤 --><resource><directory>src/main/resources</directory><filtering>true</filtering><excludes><exclude>test/*</exclude><exclude>pro/*</exclude><exclude>dev/*</exclude></excludes></resource><!-- 指定环境配置文件导入 --><resource><directory>src/main/resources/${profiles.active}</directory></resource></resources><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><configuration><source>1.8</source><target>1.8</target><delimiters><delimiter>@</delimiter></delimiters><useDefaultDelimiters>false</useDefaultDelimiters><archive><manifest><addClasspath>true</addClasspath><useUniqueVersions>false</useUniqueVersions><classpathPrefix>lib/</classpathPrefix><mainClass>xxx.xxx.xxxInterfaceMainApplication</mainClass></manifest><manifestEntries><version>${project.version}</version></manifestEntries></archive></configuration></plugin></plugins></build>
</project>

网上很多人都说需要再加忽略内置tomcat,或者servlet.api的包,其实都不需要。

主要就是

        <parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.0.3.RELEASE</version></parent>
                <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency>
<packaging>war</packaging>

<parent>     spring-boot-starter-parent    </parent>

<dependency>         spring-boot-starter-web    </dependency>

<packaging> war </packaging>

2.    修改启动方法

package com.xxx.xxxx.config;import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Executors;import javax.annotation.PostConstruct;import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.ComponentScan.Filter;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.FilterType;
import org.springframework.stereotype.Controller;@Configuration
@EnableAutoConfiguration
@ComponentScan(value = "com.xxx.xxxx", excludeFilters = { @Filter(Controller.class),@Filter(type = FilterType.ASSIGNABLE_TYPE, value = { RootConfiguration.class }) })
@MapperScan({"com.xxx.xxxx.dao"})
public class RootConfiguration extends SpringBootServletInitializer {@PostConstructpublic void postConstruct() {}@Overrideprotected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {return configureApplication(builder);}public static void main(String[] args) {configureApplication(new SpringApplicationBuilder()).run(args);}private static SpringApplicationBuilder configureApplication(SpringApplicationBuilder builder) {return builder.sources(RootConfiguration.class);}}

主要就是继承 SpringBootServletInitializer ,重写 configure 方法。

3.    问题及猜想

之前的项目就是这么配置的,用的springboot 1.5.6.RELEASE,是没有问题的。

改了新项目,升级了springboot,也加了很多东西,项目就起不来了。

本地run方法运行是没有问题的。

3.1 问题 :

启动卡死:

这是tomcat下log日志的最后几行,乍一看并没有什么问题。但是总觉得哪里不对。访问tomcat也访问不到。

[2018-07-04 06:48:10.199] [main] [DEBUG] o.h.validator.internal.xml.ValidationXmlParser - No META-INF/validation.xml found. Using annotation based configuration only.
[2018-07-04 06:48:10.205] [main] [DEBUG] o.h.validator.internal.engine.ValidatorFactoryImpl - HV000234: Using org.springframework.validation.beanvalidation.LocaleContextMessageInterpolator as ValidatorFactory-scoped message interpolator.
[2018-07-04 06:48:10.206] [main] [DEBUG] o.h.validator.internal.engine.ValidatorFactoryImpl - HV000234: Using org.hibernate.validator.internal.engine.resolver.TraverseAllTraversableResolver as ValidatorFactory-scoped traversable resolver.
[2018-07-04 06:48:10.206] [main] [DEBUG] o.h.validator.internal.engine.ValidatorFactoryImpl - HV000234: Using org.hibernate.validator.internal.util.ExecutableParameterNameProvider as ValidatorFactory-scoped parameter name provider.
[2018-07-04 06:48:10.206] [main] [DEBUG] o.h.validator.internal.engine.ValidatorFactoryImpl - HV000234: Using org.hibernate.validator.internal.engine.DefaultClockProvider as ValidatorFactory-scoped clock provider.
[2018-07-04 06:48:10.207] [main] [DEBUG] o.h.validator.internal.engine.ValidatorFactoryImpl - HV000234: Using org.hibernate.validator.internal.engine.scripting.DefaultScriptEvaluatorFactory as ValidatorFactory-scoped script evaluator factory.
[2018-07-04 06:48:10.654] [main] [WARN ] org.thymeleaf.templatemode.TemplateMode - [THYMELEAF][main] Template Mode 'HTML5' is deprecated. Using Template Mode 'HTML' instead.
[2018-07-04 06:48:10.823] [main] [INFO ] org.apache.coyote.http11.Http11NioProtocol - Starting ProtocolHandler [http-nio-8161]
[2018-07-04 06:48:10.839] [main] [INFO ] org.apache.tomcat.util.net.NioSelectorPool - Using a shared selector for servlet write/read
[2018-07-04 06:48:10.877] [main] [INFO ] com.xx.xx.xxxInterfaceMainApplication - Started xxxInterfaceMainApplication in 5.237 seconds (JVM running for 5.691)

或者卡在这:

[2018-07-04 06:48:10.056] [main] [DEBUG] o.h.validator.internal.engine.ConfigurationImpl - Setting custom MessageInterpolator of type org.springframework.validation.beanvalidation.LocaleContextMessageInterpolator
[2018-07-04 06:48:10.057] [main] [DEBUG] o.h.validator.internal.engine.ConfigurationImpl - Setting custom ConstraintValidatorFactory of type org.springframework.validation.beanvalidation.SpringConstraintValidatorFactory
[2018-07-04 06:48:10.057] [main] [DEBUG] o.h.validator.internal.engine.ConfigurationImpl - Setting custom ParameterNameProvider of type org.springframework.validation.beanvalidation.LocalValidatorFactoryBean$1
[2018-07-04 06:48:10.059] [main] [DEBUG] o.h.validator.internal.xml.ValidationXmlParser - Trying to load META-INF/validation.xml for XML based Validator configuration.
[2018-07-04 06:48:10.059] [main] [DEBUG] o.h.validator.internal.xml.ResourceLoaderHelper - Trying to load META-INF/validation.xml via user class loader
[2018-07-04 06:48:10.059] [main] [DEBUG] o.h.validator.internal.xml.ResourceLoaderHelper - Trying to load META-INF/validation.xml via TCCL
[2018-07-04 06:48:10.060] [main] [DEBUG] o.h.validator.internal.xml.ResourceLoaderHelper - Trying to load META-INF/validation.xml via Hibernate Validator's class loader
[2018-07-04 06:48:10.060] [main] [DEBUG] o.h.validator.internal.xml.ValidationXmlParser - No META-INF/validation.xml found. Using annotation based configuration only.
[2018-07-04 06:48:10.067] [main] [DEBUG] o.h.validator.internal.engine.ValidatorFactoryImpl - HV000234: Using org.springframework.validation.beanvalidation.LocaleContextMessageInterpolator as ValidatorFactory-scoped message interpolator.
[2018-07-04 06:48:10.067] [main] [DEBUG] o.h.validator.internal.engine.ValidatorFactoryImpl - HV000234: Using org.hibernate.validator.internal.engine.resolver.TraverseAllTraversableResolver as ValidatorFactory-scoped traversable resolver.
[2018-07-04 06:48:10.067] [main] [DEBUG] o.h.validator.internal.engine.ValidatorFactoryImpl - HV000234: Using org.hibernate.validator.internal.util.ExecutableParameterNameProvider as ValidatorFactory-scoped parameter name provider.
[2018-07-04 06:48:10.068] [main] [DEBUG] o.h.validator.internal.engine.ValidatorFactoryImpl - HV000234: Using org.hibernate.validator.internal.engine.DefaultClockProvider as ValidatorFactory-scoped clock provider.
[2018-07-04 06:48:10.068] [main] [DEBUG] o.h.validator.internal.engine.ValidatorFactoryImpl - HV000234: Using org.hibernate.validator.internal.engine.scripting.DefaultScriptEvaluatorFactory as ValidatorFactory-scoped script evaluator factory.
[2018-07-04 06:48:10.189] [main] [DEBUG] o.h.v.i.engine.resolver.TraversableResolvers - Cannot find javax.persistence.Persistence on classpath. Assuming non JPA 2 environment. All properties will per default be traversable.

或者卡在springboot读取banner之后。

这种问题真的是难找,也不报错。

3.2    猜想:

1    是不是springboot版本升级导致的问题,第一时间降版本,无效。

2    是不是引了多余的包,导致jar包冲突,解决了之后,无效。

3    tomcat本身问题,换tomcat版本,保证tomcat是没问题的,无效。

如果这些都做了,还是无效的话,考虑一下是不是代码的问题。

我尝试注释掉部分代码,再打包启动,如果成功了,就说明代码部分有问题。最后找到了代码中的问题。

问题代码:

/*** * 定时任务回调轮询*/
@Component
public class TaskUpdateNotify implements CommandLineRunner {public static Log logger = LogFactory.getLog(TaskUpdateNotify.class);public static final long timeFlag = 1000;@Autowiredprivate RedisClient redisClient;@Autowiredprivate ThreadHandler threadHandler;/*** 25小时以内完成8次通知(通知的间隔频率一般是:4m,10m,10m,1h,2h,6h,15h) 异步通知回调*/@Overridepublic void run(String... args) throws Exception {while (true) {// 先处理发二维码threadHandler.doNotifyAgainHandler();  //threadHandler.doPayNotifyAgainHandler();  //多线程方法//线成休息 1 minTimeUnit.MINUTES.sleep(1);}}
}

我怀疑原因是在实现 CommandLineRunner 接口,并在我在方法中 TimeUnit.MINUTES.sleep(1) 。

之后把这个方法改成了定时任务,又取消了线程sleep,就可以启动了。

最后贴一下:

启动成功的日志最后几行,应该是有tomcat容器启动的。

6-Jul-2018 06:14:03.022 信息 [localhost-startStop-1] org.springframework.boot.StartupInfoLogger.logStarted Started RootConfiguration in 6.223 seconds (JVM running for 12.622)
06-Jul-2018 06:14:03.063 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployWAR Deployment of web application archive [G:\develop\environment\apache-tomcat-8.5.32-1\webapps\preauth_interface.war] has finished in [10,773] ms
06-Jul-2018 06:14:03.064 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [G:\develop\environment\apache-tomcat-8.5.32-1\webapps\docs]
06-Jul-2018 06:14:03.086 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [G:\develop\environment\apache-tomcat-8.5.32-1\webapps\docs] has finished in [22] ms
06-Jul-2018 06:14:03.086 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [G:\develop\environment\apache-tomcat-8.5.32-1\webapps\examples]
06-Jul-2018 06:14:03.357 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [G:\develop\environment\apache-tomcat-8.5.32-1\webapps\examples] has finished in [271] ms
06-Jul-2018 06:14:03.357 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [G:\develop\environment\apache-tomcat-8.5.32-1\webapps\host-manager]
06-Jul-2018 06:14:03.386 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [G:\develop\environment\apache-tomcat-8.5.32-1\webapps\host-manager] has finished in [29] ms
06-Jul-2018 06:14:03.386 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [G:\develop\environment\apache-tomcat-8.5.32-1\webapps\manager]
06-Jul-2018 06:14:03.409 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [G:\develop\environment\apache-tomcat-8.5.32-1\webapps\manager] has finished in [23] ms
06-Jul-2018 06:14:03.410 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [G:\develop\environment\apache-tomcat-8.5.32-1\webapps\ROOT]
06-Jul-2018 06:14:03.432 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [G:\develop\environment\apache-tomcat-8.5.32-1\webapps\ROOT] has finished in [22] ms
06-Jul-2018 06:14:03.441 信息 [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"]
06-Jul-2018 06:14:03.455 信息 [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["ajp-nio-8009"]
06-Jul-2018 06:14:03.462 信息 [main] org.apache.catalina.startup.Catalina.start Server startup in 11229 ms

4.    总结

如果有报错信息一切都好说,最怕的就是这样,找不到原因。只能一点点摸索,算是分享一下吧。每个人的原因不可能一样。这种问题只能慢慢找了。多尝试几次,如果还是找不到。

就用 jar包方式 运行 springboot 项目。如果有 静态页面,就前后端分离,简单的方式 Nginx。

springboot 2.x tomcat war包部署 localhost-startStop-1 启动卡顿卡死相关推荐

  1. SpringBoot之打包成war包部署到tomcat

    SpringBoot打包成war包部署到tomcat 小编花费了九牛二虎之力,总算把SpringBoot项目成功打包成war包,其中不免遇到了一些小状况,特写此文,以便其他小伙伴们不要走我的老路,避免 ...

  2. Tomcat WAR包部署getshell

    变量名 含义 host 数据库地址 username 数据库访问用户名 password 数据库访问密码 dbname 数据库名 connection 连接 query 数据库执行语句 result ...

  3. IDEA + Tomcat + war 包部署 [ 如果看别的教程不行请看这个里 ]

    首先确保项目没问题能正常启动 点这个 很神奇吧! 对没错很有可能就是你刚才删掉的那个 图上有字看到了吗? 要不是这样请从新选择别的项目 , 或者还教程吧! 我这个恐怕不行了 . 再见! 换成这个 , ...

  4. Linux环境下服务器 Tomcat war包部署步骤

    当前工作环境是 Tomcat 8.5.31 1.常规方式 1.通过IDE打包成war 2.上传到tomcat里webapps目录下 3.重启Tomcat Note:这里注意的url后添加项目名,也就是 ...

  5. 记录这两年的学习以及简述这次基于springboot框架的课程设计和打war包部署的坑

    一.前言 一想都是满满的经历呀.如果不想看我废话,可以直接跳到后面. 1 关于编程 1.1 C.C++ 作为一名软件工程生,编程是我以后自力更生的必备技能.奈何大一的我不懂得轻重,基本没有把精力放在编 ...

  6. Linux中把文件夹打成war包,SpringBoot中maven项目打成war包部署在liunx服务器上的方法...

    说明:Spring Boot由于内嵌了如Tomcat,Jetty和Undertow这样的容器,也就是说可以直接跑起来,用不着再像Spring项目还需要外置的Tomcat等容器来进行部署工作了,通过启动 ...

  7. SpringBoot微服务项目构建war包 部署排除指定jar

    文章目录 一.构建war包部署SpringBoot项目 二.构建war包 2.1. 适用范围 2.2. 构建war包 三.部署排除指定jar 3.1. 下载排除插件 3.2. 搜索部署排除指定jar ...

  8. idea打包war包方法,以及将war包部署到tomcat详细步骤

    一.idea打包war包方法 1.在项目中找到pom.xml文件 在pom.xml文件中加入 <packaging>war</packaging> ....<name&g ...

  9. SpringBoot中文件下载、拦截器、war包部署、jar包部署

    3. SpringBoot中文件下载 将可以被下载资源放在磁盘的 D:\springbootcodes\springboot_day6\download 路径 这里我们使用jsp开发 引入依赖使tom ...

最新文章

  1. Oracle Listener 动态注册 与 静态注册
  2. Hbase完全分布式的搭建
  3. spring定时任务重复执行2次问题的解决
  4. 安全专家教你如何利用Uber系统漏洞无限制的免费乘坐?
  5. oracle常用的知识点
  6. 上传文件到阿里云OSS报错-Unable to execute HTTP request: You have no right to access this object because of buc
  7. linux安装通用plsql数据库,linux centOs中安裝好數據庫,客戶端用plsql連接oracle
  8. 图片url地址的生成获取方法
  9. 双向链表、双向循环链表
  10. 怎样使用BAT脚本实现自动按键盘的某个键
  11. 防火墙中的DMZ区域,Trust区域,Untrust区域
  12. 今日头条文章评论内容爬取
  13. 读书寄语:难过时就抱抱自己,时间治愈的,都是愿意自渡的人
  14. Android中m、mm、mmm、mma、mmma的区别
  15. C++异常传递三种不同方式介绍
  16. vue项目json格式化显示
  17. Android大厂面试真题解析大全,安卓未来路在何方
  18. 数据分析之爬虫实例-获取天气AQI数据-附python代码
  19. 超市管理系统的html页面,基于WEB的超市管理系统_站内搜索_Web开发网
  20. 计算机公共课5——演示文稿软件 PowerPoint 2010

热门文章

  1. 前端学习(3032):vue+element今日头条管理-反馈
  2. 前端学习(2932):vue中的v-show
  3. 前端学习(2906):Vite 解决了 Webpack 哪些问题
  4. [html] 实现两列等宽布局的方式有哪些?
  5. [vue] 在移动端使用vue,你觉得最佳实践有哪些?
  6. [css] 行内元素可以设置padding和margin吗?
  7. [Css] 使用css如何拉伸字体?
  8. “约见”面试官系列之常见面试题之第九十五篇之vue-router的组件组成(建议收藏)
  9. 前端学习(1304):package.json
  10. 第一百一十一期:思考 | 一文说透秒杀系统如何设计