在使用tomcat 部署应用是遇到异常如下:
Caused by: java.lang.IllegalStateException: Unable to complete the scan for annotations for web application [/xxxx] due to a StackOverflowError. Possible root causes include a too low setting for -Xss and illegal cyclic inheritance dependencies. The class hierarchy being processed was [org.bouncycastle.asn1.ASN1EncodableVector->org.bouncycastle.asn1.DEREncodableVector->org.bouncycastle.asn1.ASN1EncodableVector] at org.apache.catalina.startup.ContextConfig.checkHandlesTypes(ContextConfig.java:2188) at org.apache.catalina.startup.ContextConfig.processAnnotationsStream(ContextConfig.java:2135) at org.apache.catalina.startup.ContextConfig.processAnnotationsJar(ContextConfig.java:2010) at org.apache.catalina.startup.ContextConfig.processAnnotationsUrl(ContextConfig.java:1976) at org.apache.catalina.startup.ContextConfig.processAnnotations(ContextConfig.java:1961) at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1319) at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:878) at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:376) at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119) at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5322) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) ... 10 more分析原因:tomcat 启动扫描注解时抛出异常 StackOverflowError,扫描具体类为:
org.bouncycastle.asn1.ASN1EncodableVector->org.bouncycastle.asn1.DEREncodableVector->org.bouncycastle.asn1.ASN1EncodableVector
解决方案:$CATALINA_BASE/conf/catalina.properties
tomcat.util.scan.StandardJarScanFilter.jarsToSkip=\ bootstrap.jar,commons-daemon.jar,tomcat-juli.jar,\ annotations-api.jar,el-api.jar,jsp-api.jar,servlet-api.jar,websocket-api.jar,\ jaspic-api.jar,\ catalina.jar,catalina-ant.jar,catalina-ha.jar,catalina-storeconfig.jar,\ catalina-tribes.jar,\ jasper.jar,jasper-el.jar,ecj-*.jar,\ tomcat-api.jar,tomcat-util.jar,tomcat-util-scan.jar,tomcat-coyote.jar,\ tomcat-dbcp.jar,tomcat-jni.jar,tomcat-websocket.jar,\ tomcat-i18n-en.jar,tomcat-i18n-es.jar,tomcat-i18n-fr.jar,tomcat-i18n-ja.jar,\ tomcat-juli-adapters.jar,catalina-jmx-remote.jar,catalina-ws.jar,\ tomcat-jdbc.jar,\ tools.jar,\ commons-beanutils*.jar,commons-codec*.jar,commons-collections*.jar,\ commons-dbcp*.jar,commons-digester*.jar,commons-fileupload*.jar,\ commons-httpclient*.jar,commons-io*.jar,commons-lang*.jar,commons-logging*.jar,\ commons-math*.jar,commons-pool*.jar,\ jstl.jar,taglibs-standard-spec-*.jar,\ geronimo-spec-jaxrpc*.jar,wsdl4j*.jar,\ ant.jar,ant-junit*.jar,aspectj*.jar,jmx.jar,h2*.jar,hibernate*.jar,httpclient*.jar,\ jmx-tools.jar,jta*.jar,log4j*.jar,mail*.jar,slf4j*.jar,\ xercesImpl.jar,xmlParserAPIs.jar,xml-apis.jar,\ junit.jar,junit-*.jar,hamcrest-*.jar,easymock-*.jar,cglib-*.jar,\ objenesis-*.jar,ant-launcher.jar,\ cobertura-*.jar,asm-*.jar,dom4j-*.jar,icu4j-*.jar,jaxen-*.jar,jdom-*.jar,\ jetty-*.jar,oro-*.jar,servlet-api-*.jar,tagsoup-*.jar,xmlParserAPIs-*.jar,\ xom-*.jar, bcprov*.jar # Default list of JAR files that should be scanned that overrides the default # jarsToSkip list above. This is typically used to include a specific JAR that # has been excluded by a broad file name pattern in the jarsToSkip list. # The list of JARs to scan may be over-ridden at a Context level for individual # scan types by configuring a JarScanner with a nested JarScanFilter. tomcat.util.scan.StandardJarScanFilter.jarsToScan=\ log4j-web*.jar,log4j-taglib*.jar,log4javascript*.jar,slf4j-taglib*.jar # String cache configuration. tomcat.util.buf.StringCache.byte.enabled=true #tomcat.util.buf.StringCache.char.enabled=true #tomcat.util.buf.StringCache.trainThreshold=500000 #tomcat.util.buf.StringCache.cacheSize=5000 tomcat.util.scan.DefaultJarScanner.jarsToSkip=bcprov*.jarJAR Scannig Property Descriptiontomcat.util.scan. DefaultJarScanner.jarsToSkip
The comma-separated list of file name patterns of JARs that Tomcat will not scan for configuration information when using the JarScanner functionality. The file name pattern syntax is described in JarScanner documentation. Note that there are additional system properties that enable JARs to be excluded from specific scans rather than all scans.
The coded default is that no JARs are skipped however the system property is set in a default Tomcat installation via the $CATALINA_BASE/conf/catalina.properties file.
org.apache.catalina.startup. ContextConfig.jarsToSkipThe comma-separated list of additional filenames of JARs that Tomcat will not scan for Servlet 3.0 pluggability features.
The coded default is that no JARs are skipped however the system property is set in a default Tomcat installation via the $CATALINA_BASE/conf/catalina.properties file.
org.apache.catalina.startup. TldConfig.jarsToSkipThe comma-separated list of additional filenames of JARs that Tomcat will not scan for TLDs.
The coded default is that no JARs are skipped however the system property is set in a default Tomcat installation via the $CATALINA_BASE/conf/catalina.properties file.
Java6提供了多种算法支持,但并不完善,许多加密强度较高的算法,Java6未能提供。Bouncy Castle就是对Oracle提供的算法进行了扩展,比如IDEA、MD4、Rijndael、Serpent、Twofish等算法。关于更多Bouncy Castle的知识,请Google之,下面介绍如何在JDK中配置它。
一、下载Bouncy Castle
来这里下载最新版:http://www.bouncycastle.org/latest_releases.html (目前最新版是146),主要下载这两个文件:bcprov-jdk16-146.jar、bcprov-ext-jdk16-146.jar,如下图:
二、配置Java.security
用记事本打开%JDK_Home%\ jre\lib\security\java.security文件,找到如下9行代码:
security.provider.1=sun.security.provider.Sun
security.provider.2=sun.security.rsa.SunRsaSign
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
在这9行之后添加如下两行代码:
#增加BouncyCastleProvider
security.provider.10=org.bouncycastle.jce.provider.BouncyCastleProvider
保存Java.security文件。
同样修改%JRE_Home%\lib\security\java.security文件,加入以上两行,保存文件。
三、导入jar文件
分别复制bcprov-ext-jdk16-146.jar到"%JDK_Home%\jre\lib\ext"和"%JRE_Home%\lib\ext"目录下。
配置完成!