当我尝试在我的应用程序中上传受密码保护的PDF文件时,我收到以下异常:
如何解决这个问题?我尝试了不同的itext版本,但仍然是同样的错误。无论如何我能解决这个问题吗?感谢。
java.lang.ClassNotFoundException: org.bouncycastle.asn1.DEREncodable
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1358)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1204)
at com.itextpdf.text.pdf.PdfEncryption.<init>(PdfEncryption.java:138)
at com.itextpdf.text.pdf.PdfReader.readDecryptedDocObj(PdfReader.java:762)
at com.itextpdf.text.pdf.PdfReader.readDocObj(PdfReader.java:1133)
at com.itextpdf.text.pdf.PdfReader.readPdf(PdfReader.java:511)
at com.itextpdf.text.pdf.PdfReader.<init>(PdfReader.java:171)
at com.itextpdf.text.pdf.PdfReader.<init>(PdfReader.java:160)
at com.quepio.web.controller.TutoContentController.processChapterContent(TutoContentController.java:2582)
at com.quepio.web.controller.TutoContentController.saveOrUpdateContent(TutoContentController.java:1694)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:176)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:440)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:428)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:933)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:867)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:953)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:855)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:829)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:106)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.quepio.web.TwoFactorAuthenticationFilter.doFilterInternal(TwoFactorAuthenticationFilter.java:54)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:106)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.quepio.web.FirstLoginFilter.doFilterInternal(FirstLoginFilter.java:108)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:106)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
我正在使用以下罐子。
itext: 5.3.2
bcprov-jdk15on: 1.47
bcmail-jdk15on: 1.47
答案 0 :(得分:1)
您必须查看iText附带的POM文件:pom.xml
您会发现当前版本的iText是5.5.7:
<artifactId>itextpdf</artifactId>
<packaging>jar</packaging>
<name>iText, a Free Java-PDF library</name>
<version>5.5.7</version>
<description>iText, a free Java-PDF library</description>
现在向下滚动到依赖项并查找BouncyCastle:
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
<version>1.49</version>
<type>jar</type>
<scope>compile</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcpkix-jdk15on</artifactId>
<version>1.49</version>
<type>jar</type>
<scope>compile</scope>
<optional>true</optional>
</dependency>
如您所见,适用于5.5.7的BC版本是BC 1.49。
提供了POM文件,因此开发人员不必诉诸&#34;反复试验。&#34;如果您熟悉Maven,只需使用POM文件,您就不必担心要使用哪个BouncyCastle版本。所有依赖项都将通过Maven自动下载。
当然:您必须确保BC在服务器的CLASSPATH中也可用。您还需要特别注意确保您拥有只有一个版本的BouncyCastle。 ClassNotFoundException
并不总是意味着课程不存在。它也可能意味着存在歧义。如果在CLASSPATH中的BC的一个版本中有一个名为DEREncodable
的类,并且在类路径中的另一个BC版本中具有相同名称的类,则JVM不知道哪个类使用并且还会抛出ClassNotFoundException
。