web.jpg

最近测试服务器tomcat发布一次很慢,为了解决这个问题,特地看了tomcat的log文件,启动日志在tomcat/logs/catalina.out文件中。

1、INFO:org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory xxx.war卡顿

刺风同学就是好记性不如烂笔头的实践者,被我也用上了。

找到jdk1.x.x_xx/jre/lib/security/Java.security文件,在文件中找到securerandom.source这个设置项,将其改为:

securerandom.source=file:/dev/./urandom

重启tomcat,这一步的速度明显加快。

原理据说是这样的:

linux或者部分unix系统提供随机数设备是/dev/random 和/dev/urandom ,

两个有区别,urandom安全性没有random高,但random需要时间间隔生成随机数。jdk默认调用random。

2、 WARN: Establishing SSL connection without server's identity verification is not recommended.

具体错误是这样的:

Mon Jul 09 09:30:13 CST 2018 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.

Mon Jul 09 09:30:13 CST 2018 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.

Mon Jul 09 09:30:14 CST 2018 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.

这个错误会打几遍,每一遍都会卡一会儿,应该是在验证mysql的SSL配置。

查阅资料说mysql的高版本默认要求使用SSL链接,所以在没有配置SSL也没有说SSL不需要时,就会一直验证,验证好几遍以后放弃。

这个时间大概有1分钟。

当然,方案就是在jdbc的链接上加上userSSL=false这个参数,

jdbc:p6spy:mysql://127.0.0.1:3306/chuangke?characterEncoding=utf-8&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=Hongkong&autoReconnect=true

类似这样。

3、 禁用Springboot的JNDI功能

原来的log

10:40:24.103 [localhost-startStop-1] DEBUG org.springframework.web.context.support.StandardServletEnvironment - Replacing PropertySource 'servletContextInitParams' with 'servletContextInitParams'

10:40:24.685 [localhost-startStop-1] DEBUG org.springframework.jndi.JndiTemplate - Looking up JNDI object with name [java:comp/env/logging.exception-conversion-word]

10:40:24.686 [localhost-startStop-1] DEBUG org.springframework.jndi.JndiLocatorDelegate - Converted JNDI name [java:comp/env/logging.exception-conversion-word] not found - trying original name [logging.exception-conversion-word]. javax.naming.NameNotFoundException: Name [logging.exception-conversion-word] is not bound in this Context. Unable to find [logging.exception-conversion-word].

10:40:24.687 [localhost-startStop-1] DEBUG org.springframework.jndi.JndiTemplate - Looking up JNDI object with name [logging.exception-conversion-word]

10:40:24.687 [localhost-startStop-1] DEBUG org.springframework.jndi.JndiPropertySource - JNDI lookup for name [logging.exception-conversion-word] threw NamingException with message: Name [logging.exception-conversion-word] is not bound in this Context. Unable to find [logging.exception-conversion-word].. Returning null.

10:40:24.687 [localhost-startStop-1] DEBUG org.springframework.jndi.JndiTemplate - Looking up JNDI object with name [java:comp/env/logging.exception_conversion_word]

10:40:24.688 [localhost-startStop-1] DEBUG org.springframework.jndi.JndiLocatorDelegate - Converted JNDI name [java:comp/env/logging.exception_conversion_word] not found - trying original name [logging.exception_conversion_word]. javax.naming.NameNotFoundException: Name [logging.exception_conversion_word] is not bound in this Context. Unable to find [logging.exception_conversion_word].

10:40:24.688 [localhost-startStop-1] DEBUG org.springframework.jndi.JndiTemplate - Looking up JNDI object with name [logging.exception_conversion_word]

10:40:24.688 [localhost-startStop-1] DEBUG org.springframework.jndi.JndiPropertySource - JNDI lookup for name [logging.exception_conversion_word] threw NamingException with message: Name [logging.exception_conversion_word] is not bound in this Context. Unable to find [logging.exception_conversion_word].. Returning null.

10:40:24.689 [localhost-startStop-1] DEBUG org.springframework.jndi.JndiTemplate - Looking up JNDI object with name [java:comp/env/logging.exceptionConversionWord]

10:40:24.689 [localhost-startStop-1] DEBUG org.springframework.jndi.JndiLocatorDelegate - Converted JNDI name [java:comp/env/logging.exceptionConversionWord] not found - trying original name [logging.exceptionConversionWord]. javax.naming.NameNotFoundException: Name [logging.exceptionConversionWord] is not bound in this Context. Unable to find [logging.exceptionConversionWord].

10:40:24.689 [localhost-startStop-1] DEBUG org.springframework.jndi.JndiTemplate - Looking up JNDI object with name [logging.exceptionConversionWord]

10:40:24.689 [localhost-startStop-1] DEBUG org.springframework.jndi.JndiPropertySource - JNDI lookup for name [logging.exceptionConversionWord] threw NamingException with message: Name [logging.exceptionConversionWord] is not bound in this Context. Unable to find [logging.exceptionConversionWord].. Returning null.

10:40:24.689 [localhost-startStop-1] DEBUG org.springframework.jndi.JndiTemplate - Looking up JNDI object with name [java:comp/env/logging.exceptionconversionword]

10:40:24.689 [localhost-startStop-1] DEBUG org.springframework.jndi.JndiLocatorDelegate - Converted JNDI name [java:comp/env/logging.exceptionconversionword] not found - trying original name [logging.exceptionconversionword]. javax.naming.NameNotFoundException: Name [logging.exceptionconversionword] is not bound in this Context. Unable to find [logging.exceptionconversionword].

10:40:24.689 [localhost-startStop-1] DEBUG org.springframework.jndi.JndiTemplate - Looking up JNDI object with name [logging.exceptionconversionword]

10:40:24.690 [localhost-startStop-1] DEBUG org.springframework.jndi.JndiPropertySource - JNDI lookup for name [logging.exceptionconversionword] threw NamingException with message: Name [logging.exceptionconversionword] is not bound in this Context. Unable to find [logging.exceptionconversionword].. Returning null.

10:40:24.690 [localhost-startStop-1] DEBUG org.springframework.jndi.JndiTemplate - Looking up JNDI object with name [java:comp/env/logging.EXCEPTION-CONVERSION-WORD]

10:40:24.690 [localhost-startStop-1] DEBUG org.springframework.jndi.JndiLocatorDelegate - Converted JNDI name [java:comp/env/logging.EXCEPTION-CONVERSION-WORD] not found - trying original name [logging.EXCEPTION-CONVERSION-WORD]. javax.naming.NameNotFoundException: Name [logging.EXCEPTION-CONVERSION-WORD] is not bound in this Context. Unable to find [logging.EXCEPTION-CONVERSION-WORD].

10:40:24.690 [localhost-startStop-1] DEBUG org.springframework.jndi.JndiTemplate - Looking up JNDI object with name [logging.EXCEPTION-CONVERSION-WORD]

10:40:24.691 [localhost-startStop-1] DEBUG org.springframework.jndi.JndiPropertySource - JNDI lookup for name [logging.EXCEPTION-CONVERSION-WORD] threw NamingException with message: Name [logging.EXCEPTION-CONVERSION-WORD] is not bound in this Context. Unable to find [logging.EXCEPTION-CONVERSION-WORD].. Returning null.

10:40:24.691 [localhost-startStop-1] DEBUG org.springframework.jndi.JndiTemplate - Looking up JNDI object with name [java:comp/env/logging.EXCEPTION_CONVERSION_WORD]

10:40:24.691 [localhost-startStop-1] DEBUG org.springframework.jndi.JndiLocatorDelegate - Converted JNDI name [java:comp/env/logging.EXCEPTION_CONVERSION_WORD] not found - trying original name [logging.EXCEPTION_CONVERSION_WORD]. javax.naming.NameNotFoundException: Name [logging.EXCEPTION_CONVERSION_WORD] is not bound in this Context. Unable to find [logging.EXCEPTION_CONVERSION_WORD].

10:40:24.691 [localhost-startStop-1] DEBUG org.springframework.jndi.JndiTemplate - Looking up JNDI object with name [logging.EXCEPTION_CONVERSION_WORD]

10:40:24.691 [localhost-startStop-1] DEBUG org.springframework.jndi.JndiPropertySource - JNDI lookup for name [logging.EXCEPTION_CONVERSION_WORD] threw NamingException with message: Name [logging.EXCEPTION_CONVERSION_WORD] is not bound in this Context. Unable to find [logging.EXCEPTION_CONVERSION_WORD].. Returning null.

10:40:24.691 [localhost-startStop-1] DEBUG org.springframework.jndi.JndiTemplate - Looking up JNDI object with name [java:comp/env/logging.EXCEPTIONCONVERSIONWORD]

10:40:24.691 [localhost-startStop-1] DEBUG org.springframework.jndi.JndiLocatorDelegate - Converted JNDI name [java:comp/env/logging.EXCEPTIONCONVERSIONWORD] not found - trying original name [logging.EXCEPTIONCONVERSIONWORD]. javax.naming.NameNotFoundException: Name [logging.EXCEPTIONCONVERSIONWORD] is not bound in this Context. Unable to find [logging.EXCEPTIONCONVERSIONWORD].

10:40:24.691 [localhost-startStop-1] DEBUG org.springframework.jndi.JndiTemplate - Looking up JNDI object with name [logging.EXCEPTIONCONVERSIONWORD]

10:40:24.691 [localhost-startStop-1] DEBUG org.springframework.jndi.JndiPropertySource - JNDI lookup for name [logging.EXCEPTIONCONVERSIONWORD] threw NamingException with message: Name [logging.EXCEPTIONCONVERSIONWORD] is not bound in this Context. Unable to find [logging.EXCEPTIONCONVERSIONWORD].. Returning null.

10:40:24.691 [localhost-startStop-1] DEBUG org.springframework.jndi.JndiTemplate - Looking up JNDI object with name [java:comp/env/logging_exception-conversion-word]

10:40:24.692 [localhost-startStop-1] DEBUG org.springframework.jndi.JndiLocatorDelegate - Converted JNDI name [java:comp/env/logging_exception-conversion-word] not found - trying original name [logging_exception-conversion-word]. javax.naming.NameNotFoundException: Name [logging_exception-conversion-word] is not bound in this Context. Unable to find [logging_exception-conversion-word].

10:40:24.692 [localhost-startStop-1] DEBUG org.springframework.jndi.JndiTemplate - Looking up JNDI object with name [logging_exception-conversion-word]

10:40:24.692 [localhost-startStop-1] DEBUG org.springframework.jndi.JndiPropertySource - JNDI lookup for name [logging_exception-conversion-word] threw NamingException with message: Name [logging_exception-conversion-word] is not bound in this Context. Unable to find [logging_exception-conversion-word].. Returning null.

10:40:24.692 [localhost-startStop-1] DEBUG org.springframework.jndi.JndiTemplate - Looking up JNDI object with name [java:comp/env/logging_exception_conversion_word]

10:40:24.692 [localhost-startStop-1] DEBUG org.springframework.jndi.JndiLocatorDelegate - Converted JNDI name [java:comp/env/logging_exception_conversion_word] not found - trying original name [logging_exception_conversion_word]. javax.naming.NameNotFoundException: Name [logging_exception_conversion_word] is not bound in this Context. Unable to find [logging_exception_conversion_word].

10:40:24.692 [localhost-startStop-1] DEBUG org.springframework.jndi.JndiTemplate - Looking up JNDI object with name [logging_exception_conversion_word]

10:40:24.692 [localhost-startStop-1] DEBUG org.springframework.jndi.JndiPropertySource - JNDI lookup for name [logging_exception_conversion_word] threw NamingException with message: Name [logging_exception_conversion_word] is not bound in this Context. Unable to find [logging_exception_conversion_word].. Returning null.

10:40:24.692 [localhost-startStop-1] DEBUG org.springframework.jndi.JndiTemplate - Looking up JNDI object with name [java:comp/env/logging_exceptionConversionWord]

10:40:24.692 [localhost-startStop-1] DEBUG org.springframework.jndi.JndiLocatorDelegate - Converted JNDI name [java:comp/env/logging_exceptionConversionWord] not found - trying original name [logging_exceptionConversionWord]. javax.naming.NameNotFoundException: Name [logging_exceptionConversionWord] is not bound in this Context. Unable to find [logging_exceptionConversionWord].

10:40:24.692 [localhost-startStop-1] DEBUG org.springframework.jndi.JndiTemplate - Looking up JNDI object with name [logging_exceptionConversionWord]

10:40:24.692 [localhost-startStop-1] DEBUG org.springframework.jndi.JndiPropertySource - JNDI lookup for name [logging_exceptionConversionWord] threw NamingException with message: Name [logging_exceptionConversionWord] is not bound in this Context. Unable to find [logging_exceptionConversionWord].. Returning null.

10:40:24.692 [localhost-startStop-1] DEBUG org.springframework.jndi.JndiTemplate - Looking up JNDI object with name [java:comp/env/logging_exceptionconversionword]

10:40:24.692 [localhost-startStop-1] DEBUG org.springframework.jndi.JndiLocatorDelegate - Converted JNDI name [java:comp/env/logging_exceptionconversionword] not found - trying original name [logging_exceptionconversionword]. javax.naming.NameNotFoundException: Name [logging_exceptionconversionword] is not bound in this Context. Unable to find [logging_exceptionconversionword].

10:40:24.692 [localhost-startStop-1] DEBUG org.springframework.jndi.JndiTemplate - Looking up JNDI object with name [logging_exceptionconversionword]

参考配置教程修改。

摘要:在实际项目开发中使用springboot的时候,可以使用jar包的方式运行项目,也可以将springboot项目打成war包使用。springboot war包运行可能会出现

[localhost-startStop-1] DEBUG org.springframework.jndi.JndiLocatorDelegate - Converted JNDI name [java:comp/env/LOGGING.pattern_level] not found - trying original name [LOGGING.pattern_level]. javax.naming.NameNotFoundException: Name [LOGGING.pattern_level] is not bound in this Context. Unable to find [LOGGING.pattern_level]。

反正就是诸如此类的问题吧。

上述的问题,在高版本的spring boot中会出现的,低版本不会出现这个问题。因为高版本中引入了JNDI查询的操作。

解决方案:

在项目的根目录中新建spring.properties配置文件,如下图所示:

image.png

添加属性以及值,如下所示:

spring.jndi.ignore=true

原理:

打开StandardServletEnvironment类,该类中的customizePropertySources方法如下:

public static final String JNDI_PROPERTY_SOURCE_NAME = "jndiProperties";

protected void customizePropertySources(MutablePropertySources propertySources) {

propertySources.addLast(new StubPropertySource(SERVLET_CONFIG_PROPERTY_SOURCE_NAME));

propertySources.addLast(new StubPropertySource(SERVLET_CONTEXT_PROPERTY_SOURCE_NAME));

if (JndiLocatorDelegate.isDefaultJndiEnvironmentAvailable()) {

propertySources.addLast(new JndiPropertySource(JNDI_PROPERTY_SOURCE_NAME));

}

super.customizePropertySources(propertySources);

}

JndiLocatorDelegate.isDefaultJndiEnvironmentAvailable()代码如下:

public static final String IGNORE_JNDI_PROPERTY_NAME = "spring.jndi.ignore";

private static final boolean shouldIgnoreDefaultJndiEnvironment =

SpringProperties.getFlag(IGNORE_JNDI_PROPERTY_NAME);

public static boolean isDefaultJndiEnvironmentAvailable() {

//如果忽略jndi则返回false

if (shouldIgnoreDefaultJndiEnvironment) {

return false;

}

try {

//准备jndi环境

new InitialContext().getEnvironment();

return true;

}

catch (Throwable ex) {

return false;

}

}

通过上文可知:

1、如果我们需要忽略jndi则可以配置spring.jndi.ignore值为true即可。

2、在哪里配置呢?我们不妨跟进SpringProperties类中的getFlag方法。

spring.jndi.ignore获取原理

SpringProperties类的getFlag方法如下所示:

public static boolean getFlag(String key) {

return Boolean.parseBoolean(getProperty(key));

}

继续跟进getProperty方法,如下所示:

public static String getProperty(String key) {

//获取spring.jndi.ignore值

String value = localProperties.getProperty(key);

if (value == null) {

try {//获取系统的变量

value = System.getProperty(key);

}

catch (Throwable ex) {

}

}

return value;

}

上述的方法可以总结如下:

从localProperties集合中获取spring.jndi.ignore属性,如果没有获取到则直接从环境变量中进行获取。localProperties集合在哪里初始化的呢?我们看一下SpringProperties类中的静态代码块,如下所示:

private static final String PROPERTIES_RESOURCE_LOCATION = "spring.properties";

static {

try {

ClassLoader cl = SpringProperties.class.getClassLoader();

URL url = (cl != null ? cl.getResource(PROPERTIES_RESOURCE_LOCATION) :ClassLoader.getSystemResource(PROPERTIES_RESOURCE_LOCATION));

if (url != null) {

logger.info("Found 'spring.properties' file in local classpath");

InputStream is = url.openStream();

try {

localProperties.load(is);

}

finally {

is.close();

}

}

}

catch (IOException ex) {

}

}

}

看到上面的代码,我们明白了,原来这里是直接读取跟目录中的spring.properties文件中的所有属性。看到这里,焕然大悟。原来如此。

调试中,我修改了application.yml或者application-dev.yml配置文件,在文件中加入了spring.jndi.ignore=true均为生效,必须新建一个spring.properties,我没有验证spring.yml行不行。

重启tomcat容器,没有jndi的警告日志了。

注意:这种日志如果在本地以直接运行springboot的入口文件的方式启动,是没有的,只有当打成war包,放在tomcat里,启动tomcat/bin/startup.sh时才会有。

经过几步修改,tomcat启动速度明显提高。

java war启动慢_解决springboot war包在tomcat部署时启动慢的问题相关推荐

  1. 记一次定位解决SpringBoot中内嵌Tomcat的Bug问题

    你知道的越多,不知道的就越多,业余的像一棵小草! 你来,我们一起精进!你不来,我和你的竞争对手一起精进! 编辑:业余草 segmentfault.com/a/1190000038760707 推荐:h ...

  2. Java多线程读取excel文件_解决springboot 多线程使用MultipartFile读取excel文件内容报错问题...

    springboot项目开启多线程 启动类加注解开启 @EnableAsync,实现类方法加注解 @Async 前端页面 报错信息 java.io.FileNotFoundException: C:\ ...

  3. java 实体类返回大写_解决springboot bean中大写的字段返回变成小写的问题

    例如我的bean中有以下4个字段 private String code; private String _TOKENUUMS; private String TGC; private String ...

  4. springboot公共模块打包_解决SpringBoot多模块发布时99%的问题?

    每天都会分享Java架构文章,喜欢的朋友关注我.ps:文末有彩蛋,惊喜等着你 如果使用的是 SpringBoot 多模块的项目,在发布的时候可能遇到各种各样的问题.本文归纳了以下 8 个原则和发布时经 ...

  5. 将项目打成war包并用tomcat部署的方法,步骤及注意点

    部署的遇到第一个问题,就是tomcat和jdk的环境问题: 首先 理解为啥要关注这二者的环境呢?他们还是有关系的–tomcat 作为比较流行的java Web服务器也是用java来实现的一个比较大的软 ...

  6. IDEA打包war包及Tomcat部署war包

    1.准备工作 IntelliJ IDEA 开发工具 --我的版本是IDEA 2021.2.1 可以正常运行的Java项目 Tomcat 9.0.56 2.打包war包流程 按下图操作打开 Projec ...

  7. Tomcat部署时war和war exploded区别以及平时踩得坑

    war和war exploded的区别 在使用IDEA开发项目的时候,部署Tomcat的时候通常会出现下边的情况: 是选择war还是war exploded 这里首先看一下他们两个的区别: war模式 ...

  8. dell进入u盘启动模式_戴尔如何进入bios设置u盘启动项?

    在快启动我们有很多文章说到了戴尔具体型号机子的U盘启动设置说明,比如戴尔灵越14 7000笔记本电脑u盘启动设置.其中大部分戴尔电脑的U盘启动设置都是相同的,因此这篇文章可以作为设置的参考来进行查看. ...

  9. java war包更新 部署_关于Linux系统下基于Tomcat部署和升级war包的详细过程

    1.首先Linux先安装java,Tomcat 中间件规范要求: 1)         软件必须下载到/services/download_soft_v        --------(用xftp上传 ...

最新文章

  1. android 图片列表,Android 列表使用(ListView GridView Gallery图片计时滚动)
  2. amazon redshift 分析型数据库特点——本质还是列存储
  3. python语言if语句-Python在if语句中等同于(logical-and)
  4. 抖音访问太频繁-设备注册分析
  5. axure 组件_技巧分享 | Axure后台组件制作的全过程
  6. 5-输入输出系统IO
  7. c++中4个与类型转换相关的关键字总结
  8. java.sql.SQLException: null, message from server: “Host ‘xxx.xxx.xxx.xxx‘ is not allowed to
  9. Spring Boot引起的“堆外内存泄漏”排查及经验总结 1
  10. 第三方魔兽金币交易平台的影响力会很快地褪去
  11. 百家号在线视频编辑器的技术演进
  12. ACR122U读写器真假判断
  13. Android逆向:某鹰直播Lua脚本解密
  14. 小提琴1234567位置图解_小提琴的指法图
  15. 最全iOS12捷径库收集整理,iOS12捷径推荐
  16. java 基础: 一些稀奇古怪的好东西总结 丰富知识面
  17. 拟物化设计与扁平化设计
  18. 敏感词过滤的算法原理之 Aho-Corasick 算法
  19. Redis 会被Dragonfly替代?
  20. java fastmethod_Java FastMath.cbrt方法代码示例

热门文章

  1. 算法设计与分析第一章递推算法
  2. java校招我的归纳总结
  3. DRM之Microsoft PlayReady学习入门(一)
  4. 采用原笔迹电子签名有什么好处
  5. 计算机中用于汉字处理的是什么意思,用于汉字输出的是什么编码
  6. 边缘计算:电信运营商5G时代战略转型的关键一步
  7. 面试知识点梳理一:概率论和线性代数
  8. Pandas - Review
  9. 日食恐慌!运营商面临严峻挑战!
  10. 手把手教你搭建SpringCloud项目(九)集成OpenFeign服务接口调用