java 在Spring集成应用程序启动时生成种子时发生意外的CryptoAPI故障

anauzrmj  于 2023-01-07  发布在  Java
关注(0)|答案(2)|浏览(84)

我有一个spring集成应用程序,它在Windows(Windows Server 2012 R2)上启动时失败,使用jdk1.8.0_151-X64,但有以下例外:

INFO [main] o.s.c.s.ClassPathXmlApplicationContext [AbstractApplicationContext.java:574] Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@1b604f19: startup date [Thu Jul 04 15:17:39 CEST 2019]; root of context hierarchy
INFO [main] o.s.b.f.x.XmlBeanDefinitionReader [XmlBeanDefinitionReader.java:317] Loading XML bean definitions from class path resource [cpm-dml-common-error.xml]
INFO [main] o.s.b.f.x.XmlBeanDefinitionReader [XmlBeanDefinitionReader.java:317] Loading XML bean definitions from URL [jar:file:/D:/CPM/dml/adapter-versions/cpm-dml-subscriber-bla-1.2.0.RELEASE/lib/cpm-dml-common-3.0.0.RELEASE.jar!/dml-file-shutdown.xml]
ERROR [main] c.h.g.d.i.u.Adapter [Adapter.java:73] Exception initialising application context.  Process will exit
org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Failed to import bean definitions from URL location [classpath*:dml-file-shutdown.xml]
Offending resource: class path resource [cpm-dml-subscriber-bla-top-level.xml]; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from URL [jar:file:/D:/CPM/dml/adapter-versions/cpm-dml-subscriber-bla-1.2.0.RELEASE/lib/cpm-dml-common-3.0.0.RELEASE.jar!/dml-file-shutdown.xml]; nested exception is java.lang.InternalError: Unexpected CryptoAPI failure generating seed
    at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:70) ~[spring-beans-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:85) ~[spring-beans-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:76) ~[spring-beans-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.importBeanDefinitionResource(DefaultBeanDefinitionDocumentReader.java:229) ~[spring-beans-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseDefaultElement(DefaultBeanDefinitionDocumentReader.java:180) ~[spring-beans-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:165) ~[spring-beans-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.doRegisterBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:138) ~[spring-beans-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:94) ~[spring-beans-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:508) ~[spring-beans-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:392) ~[spring-beans-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:336) ~[spring-beans-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:304) ~[spring-beans-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:181) ~[spring-beans-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:217) ~[spring-beans-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:188) ~[spring-beans-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:252) ~[spring-beans-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:127) ~[spring-context-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:93) ~[spring-context-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:129) ~[spring-context-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:605) ~[spring-context-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:509) ~[spring-context-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139) ~[spring-context-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83) ~[spring-context-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at c.h.g.d.i.u.Adapter.<init>(Adapter.java:47) ~[dml_core-5.0.0.RELEASE.jar:5.0.0.RELEASE]
    at c.h.g.d.i.u.Adapter.main(Adapter.java:70) ~[dml_core-5.0.0.RELEASE.jar:5.0.0.RELEASE]
Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from URL [jar:file:/D:/CPM/dml/adapter-versions/cpm-dml-subscriber-bla-1.2.0.RELEASE/lib/cpm-dml-common-3.0.0.RELEASE.jar!/dml-file-shutdown.xml]; nested exception is java.lang.InternalError: Unexpected CryptoAPI failure generating seed
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:414) ~[spring-beans-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:336) ~[spring-beans-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:304) ~[spring-beans-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:181) ~[spring-beans-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:217) ~[spring-beans-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.importBeanDefinitionResource(DefaultBeanDefinitionDocumentReader.java:223) ~[spring-beans-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    ... 21 common frames omitted
Caused by: java.lang.InternalError: Unexpected CryptoAPI failure generating seed
    at sun.security.provider.NativeSeedGenerator.getSeedBytes(NativeSeedGenerator.java:62) ~[na:1.8.0_151]
    at sun.security.provider.SeedGenerator.generateSeed(SeedGenerator.java:144) ~[na:1.8.0_151]
    at sun.security.provider.SecureRandom$SeederHolder.<clinit>(SecureRandom.java:203) ~[na:1.8.0_151]
    at sun.security.provider.SecureRandom.engineNextBytes(SecureRandom.java:221) ~[na:1.8.0_151]
    at java.security.SecureRandom.nextBytes(SecureRandom.java:468) ~[na:1.8.0_151]
    at java.util.UUID.randomUUID(UUID.java:145) ~[na:1.8.0_151]
    at org.springframework.integration.jmx.config.MBeanExporterParser.resolveId(MBeanExporterParser.java:87) ~[spring-integration-jmx-4.1.6.RELEASE.jar:na]
    at org.springframework.beans.factory.xml.AbstractBeanDefinitionParser.parse(AbstractBeanDefinitionParser.java:64) ~[spring-beans-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.beans.factory.xml.NamespaceHandlerSupport.parse(NamespaceHandlerSupport.java:74) ~[spring-beans-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.integration.config.xml.AbstractIntegrationNamespaceHandler.parse(AbstractIntegrationNamespaceHandler.java:58) ~[spring-integration-core-4.1.6.RELEASE.jar:na]
    at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1411) ~[spring-beans-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1401) ~[spring-beans-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:168) ~[spring-beans-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.doRegisterBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:138) ~[spring-beans-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:94) ~[spring-beans-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:508) ~[spring-beans-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:392) ~[spring-beans-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    ... 26 common frames omitted

应用程序是服务器上运行的唯一java进程。重新启动应用程序不起作用,同样的异常不断出现。
我测试过在jdk1.7.0_11-x64上运行其他Spring集成应用程序,它们大部分时间运行良好,但有时候(~1/20)仍会遇到此异常:简单的重新启动解决了该问题。
这个异常的可能原因是什么?我该如何修复?

f1tvaqid

f1tvaqid1#

看起来这是Java端的某种bug:https://bugs.openjdk.java.net/browse/JDK-8057894
同时,堆栈跟踪将我们引导到MBeanExporterParser中的以下代码:

if (id.matches(IntegrationMBeanExporter.class.getName() + "#[0-9]+")) {
        //  Randomize the name in case there are multiple contexts in the same JVM
        id += "#" + UUID.randomUUID();
    }

是否介意为<int-jmx:mbean-export>添加一个显式的id

h9vpoimq

h9vpoimq2#

这个问题似乎至少有两个方面:

  • 一个试图生成随机数的代码,在本例中是Spring的一部分。
  • 负责根据安全提供程序生成实际随机数的JDK代码。sun.security.provider.Sun。

鉴于这是一个间歇性问题(最初提到的1/20),很可能是由于安全提供者端的锁争用或速度慢。
一种解决方案是尽量减少对随机数的调用,在这种情况下正确配置Springmbean。
However, the random number generation is not only linked to Spring mbeans, so the same underlying problem can be seen in different APIs, that's the 2nd part of this problem. sun.security.provider.Sun is the default security provider for the JDK or at least the first on the list of security providers at JAVA_HOME/jre/lib/security/java.security file, and responsible to generate these random numbers.
这个问题的第二个方面是随机数生成不仅仅与Spring MBean有关;相反,它与各种API相关,在这些API中可以看到相同的基本问题。sun.security.provider。Sun负责生成这些随机数,并且是JDK的默认安全提供者,或者至少是JAVA_HOME/jre/lib/security/java.security文件中的安全提供者列表中的第一个。
例如:

security.provider.1=sun.security.provider.Sun
security.provider.2=sun.security.rsa.SunRsaSign
security.provider.3=sun.security.ec.SunEC
security.provider.4=com.sun.net.ssl.internal.ssl.Provider
security.provider.5=com.sun.crypto.provider.SunJCE
security.provider.6=sun.security.jgss.SunProvider
security.provider.7=com.sun.security.sasl.Provider
security.provider.8=org.jcp.xml.dsig.internal.dom.XMLDSigRI
security.provider.9=sun.security.smartcardio.SunPCSC
security.provider.10=sun.security.mscapi.SunMSCAPI

请注意,有问题的安全提供程序位于列表的顶部,因此第二种可能的解决方案是禁用它,这意味着应该将具有索引的列表重新构造为:

security.provider.1=sun.security.rsa.SunRsaSign    
    #security.provider.1=sun.security.provider.Sun
    security.provider.2=sun.security.ec.SunEC
    security.provider.3=com.sun.net.ssl.internal.ssl.Provider
    security.provider.4=com.sun.crypto.provider.SunJCE
    security.provider.5=sun.security.jgss.SunProvider
    security.provider.6=com.sun.security.sasl.Provider
    security.provider.7=org.jcp.xml.dsig.internal.dom.XMLDSigRI
    security.provider.8=sun.security.smartcardio.SunPCSC
    security.provider.9=sun.security.mscapi.SunMSCAPI

Take a backup copy of the java.security file before, and try first in a non-productive environment.

相关问题