>>>我的博客<<<
最近測試服務(wù)器tomcat發(fā)布一次很慢鉴象,為了解決這個(gè)問題,特地看了tomcat的log文件何鸡,啟動(dòng)日志在tomcat/logs/catalina.out文件中纺弊。
1、INFO:org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory xxx.war卡頓
刺風(fēng)同學(xué)就是好記性不如爛筆頭的實(shí)踐者骡男,被我也用上了淆游。
找到j(luò)dk1.x.x_xx/jre/lib/security/Java.security文件,在文件中找到securerandom.source這個(gè)設(shè)置項(xiàng)隔盛,將其改為:
securerandom.source=file:/dev/./urandom
重啟tomcat,這一步的速度明顯加快犹菱。
原理據(jù)說是這樣的:
linux或者部分unix系統(tǒng)提供隨機(jī)數(shù)設(shè)備是/dev/random 和/dev/urandom ,
兩個(gè)有區(qū)別骚亿,urandom安全性沒有random高,但random需要時(shí)間間隔生成隨機(jī)數(shù)熊赖。jdk默認(rèn)調(diào)用random来屠。
2、 WARN: Establishing SSL connection without server's identity verification is not recommended.
具體錯(cuò)誤是這樣的:
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.
這個(gè)錯(cuò)誤會(huì)打幾遍震鹉,每一遍都會(huì)卡一會(huì)兒俱笛,應(yīng)該是在驗(yàn)證mysql的SSL配置。
查閱資料說mysql的高版本默認(rèn)要求使用SSL鏈接传趾,所以在沒有配置SSL也沒有說SSL不需要時(shí)迎膜,就會(huì)一直驗(yàn)證,驗(yàn)證好幾遍以后放棄浆兰。
這個(gè)時(shí)間大概有1分鐘磕仅。
當(dāng)然珊豹,方案就是在jdbc的鏈接上加上userSSL=false這個(gè)參數(shù),
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]
參考配置教程修改。
摘要:在實(shí)際項(xiàng)目開發(fā)中使用springboot的時(shí)候劫恒,可以使用jar包的方式運(yùn)行項(xiàng)目贩幻,也可以將springboot項(xiàng)目打成war包使用。springboot war包運(yùn)行可能會(huì)出現(xiàn)
[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中會(huì)出現(xiàn)的憔辫,低版本不會(huì)出現(xiàn)這個(gè)問題趣些。因?yàn)楦甙姹局幸肓薐NDI查詢的操作。
解決方案:
在項(xiàng)目的根目錄中新建spring.properties
配置文件螺垢,如下圖所示:
添加屬性以及值喧务,如下所示:
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 {
//準(zhǔn)備jndi環(huán)境
new InitialContext().getEnvironment();
return true;
}
catch (Throwable ex) {
return false;
}
}
通過上文可知:
1枉圃、如果我們需要忽略jndi則可以配置spring.jndi.ignore
值為true即可功茴。
2、在哪里配置呢孽亲?我們不妨跟進(jìn)SpringProperties
類中的getFlag方法坎穿。
spring.jndi.ignore獲取原理
SpringProperties類的getFlag方法如下所示:
public static boolean getFlag(String key) {
return Boolean.parseBoolean(getProperty(key));
}
繼續(xù)跟進(jìn)getProperty方法,如下所示:
public static String getProperty(String key) {
//獲取spring.jndi.ignore值
String value = localProperties.getProperty(key);
if (value == null) {
try {//獲取系統(tǒng)的變量
value = System.getProperty(key);
}
catch (Throwable ex) {
}
}
return value;
}
上述的方法可以總結(jié)如下:
從localProperties集合中獲取spring.jndi.ignore
屬性返劲,如果沒有獲取到則直接從環(huán)境變量中進(jìn)行獲取玲昧。localProperties集合在哪里初始化的呢?我們看一下SpringProperties類中的靜態(tài)代碼塊篮绿,如下所示:
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文件中的所有屬性亲配〕居Γ看到這里,煥然大悟吼虎。原來如此犬钢。
- 調(diào)試中,我修改了
application.yml
或者application-dev.yml
配置文件思灰,在文件中加入了spring.jndi.ignore=true
均為生效玷犹,必須新建一個(gè)spring.properties
,我沒有驗(yàn)證spring.yml
行不行洒疚。
重啟tomcat容器歹颓,沒有jndi的警告日志了坯屿。
注意:這種日志如果在本地以直接運(yùn)行springboot的入口文件的方式啟動(dòng),是沒有的晴股,只有當(dāng)打成war包愿伴,放在tomcat里,啟動(dòng)tomcat/bin/startup.sh
時(shí)才會(huì)有电湘。
經(jīng)過幾步修改隔节,tomcat啟動(dòng)速度明顯提高。
部署慢修改原文:https://www.cnblogs.com/mycifeng/p/6972446.html
禁用jndi方式原文:https://blog.csdn.net/qq_30739519/article/details/78536965