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

大家好,我是烤鸭:   

    关于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。

    

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/412939.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

高可用Eureka注册中心配置说明(双机部署)

目 录 1. 高可用EureKa注册中心示意图 2. Eureka实例相互注册配置 3. 微服务注册到Eureka配置 4. 启动步骤及配置成功检查 5. 说明事项 1. 高可用EureKa注册中心示意图 Spring Cloud的Eureka Server的高可用实际上就是将自己作为服务向其他服注册中心注册自己&#xff0c;形成…

sql 把特定数据排在最前面

第一法】 select * from table where nameD UNION ALL select * from table where name<>D 第二法】SELECT CASE WHEN [name]D THEN 0 ELSE 1 END FLAG,* FROM TABLE order by flag asc

[css] css的linear-gradient有什么作用呢?

[css] css的linear-gradient有什么作用呢&#xff1f; 概念&#xff1a;线性渐变,向下/向上/向左/向右/对角方向,为了创建一个线性渐变&#xff0c;你必须至少定义两种颜色结点。颜色结点即你想要呈现平稳过渡的颜色。同时&#xff0c;你也可以设置一个起点和一个方向&#xff…

elasticsearch 6.x (四) 单一文档 API 介绍和使用 index和get API

大家好&#xff0c;我是烤鸭&#xff1a;今天分享的是官网6.x 单一文档(Single document APIs)APIs。本文这是部分翻译&#xff0c;如果想看全部的&#xff0c;还是建议阅读官方api。链接&#xff1a;https://www.elastic.co/guide/en/elasticsearch/reference/current/docs…

Dockerfile语法

Dockerfile 语法示例 Dockerfile语法由两部分构成&#xff0c;注释和命令参数 # Line blocks used for commentingcommand argument argument ..一个简单的例子&#xff1a; # Print "Hello docker!"RUN echo "Hello docker!"Dockerfile 命令 Dockerfile有…

[css] 会引起Reflow和Repaint的操作有哪些?

[css] 会引起Reflow和Repaint的操作有哪些&#xff1f; 页面布局和几何信息(比如&#xff1a;增加删除dom&#xff0c;改变元素位置或者尺寸等)发生改变时&#xff0c;会触发Reflow。 给dom节点添加样式&#xff0c;会触发Repaint。 触发Reflow一定会引起Repaint&#xff0c;触…

Centos7离线安装Mysql8

一&#xff0c;下载tar包 1&#xff0c;直接下载&#xff1a;https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.15-1.el7.x86_64.rpm-bundle.tar 2&#xff0c;百度网盘&#xff1a;https://pan.baidu.com/s/1V180rx0FVFuUOrnPMqrVpQ 提取码&#xff1a;08jx 二&…

[css] 你有用过clip-path吗?说说你对它的理解和它都有哪些运用场景?

[css] 你有用过clip-path吗&#xff1f;说说你对它的理解和它都有哪些运用场景&#xff1f; clip-path属性可以创建一个只有元素的部分区域可以显示的剪切区域它的值可以为以下几种: 用 表示剪切元素的路径: 一种形状&#xff0c;其大小和位置由<几何盒>值定义。如果没有…

elasticsearch 6.x (五) 单一文档 API 介绍和使用 update和delete API

大家好&#xff0c;我是烤鸭&#xff1a;今天分享的是官网6.x 单一文档(Single document APIs)APIs。本文这是部分翻译&#xff0c;如果想看全部的&#xff0c;还是建议阅读官方api。链接&#xff1a;https://www.elastic.co/guide/en/elasticsearch/reference/current/docs…

Linux 编译安装BIND

下载网址&#xff1a;www.isc.org 首选需要安装开发环境&#xff0c;包括openssl等开发包&#xff1b; 解压文件 tar -zxvf bind*.tar.gz 创建named使用的系统用户 groupadd -g 53 -r named useradd -u 53 -r named 编译安装 …

Mysql设置忽略大小写

如果你不在意数据的话直接删除数据&#xff08;删数据库前请备份&#xff09; 1 停止MySQL 2 删除 MySQL的数据 /var/lib/mysql 3 修改该 lower_case_table_names 1 4 启动 mysql 4 搞定 解决Navicat连接MySQL出现1251-Client does not support authentication protocol requ…

[css] 你是怎么选择resetting和normalizing的?为什么?

[css] 你是怎么选择resetting和normalizing的&#xff1f;为什么&#xff1f; 一般选择normalizeReset: 比较粗暴的处理方式&#xff0c;不管有用没有统统处理成一种方式&#xff0c;如果是临时页面会采用。* {margin: 0;padding: 0;box-sizing: border-box; } *::after, *::be…

http://www.a.cn/?a.b=1 取a.b的值

$_GET[a_b] 转载于:https://www.cnblogs.com/liiu/p/9909286.html

解决svn:E200030: sqlite[S11]:database disk image is malformed

一&#xff0c;问题产生原因&#xff1a;我的电脑突然蓝屏&#xff0c;然后重启电脑后&#xff0c;更新项目提示这个鬼东西 二&#xff0c;解决方法&#xff1a; 1&#xff0c;下载sqlite3并把sqlite3.exe放到项目文件夹.svn同级目录 2&#xff0c;在项目文件夹的上面路径那里…

Java 正则表达式 工具类 中文 英文 email 手机号 身份证 数字 日期

大家好&#xff0c;我是烤鸭&#xff1a; 分享一个Java版本的正则校验工具类。 Validation.java package com.xxx.xxx.common.utils;import java.util.regex.Matcher; import java.util.regex.Pattern; /*** 验证工具类* author admin**/ public class Validation { //--…

[css] position跟margin collapse这些特性相互叠加后会怎么样?

[css] position跟margin collapse这些特性相互叠加后会怎么样&#xff1f; 怎样防止外边距重叠&#xff1f;底部元素脱离文档流(float: left/right || position: absolute/fixed)个人简介 我是歌谣&#xff0c;欢迎和大家一起交流前后端知识。放弃很容易&#xff0c; 但坚持一…

Python_全局变量的定义

1.在my套件下新建一个关键字systemkey并进行脚本的编写&#xff1a;创建一个${var1}变量&#xff0c;并赋值为aaaaaaaaaa Set Global Variable ${var1} aaaaaaaaaa 2.在全局&#xff08;最顶部文件夹&#xff09;中Suite Setup→Edit→systemkey&#xff08…

Tomcat设置URL兼容特殊符号

catalina.properties配置&#xff1a; tomcat.util.http.parser.HttpParser.requestTargetAllow|{}[] org.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASHtrueserver.xml配置&#xff1a; <Connector port"80" protocol"HTTP/1.1"connectionTi…

[css] 移动端的布局用过媒体查询吗?写一个试试

[css] 移动端的布局用过媒体查询吗&#xff1f;写一个试试 使用过Demo<style>.demo {width: 100px;height: 100px;background: #000000;}media only screen and (min-width: 680px ) {.demo {background: red;}} </style> <div class"demo"></d…

java 实现 常见排序算法(一) 冒泡排序

大家好&#xff0c;我是烤鸭&#xff1a; 今天分享一下基础排序算法之冒泡排序。 1. 冒泡排序&#xff1a; 原理&#xff1a;比较两个相邻的元素&#xff0c;将较大的元素交换至右端。 思路&#xff1a;依次比较相邻的两个数&#xff0c;将小数放在前面&#xff0c;大…