Org.apache.catalina.util.DefaultAnnotationProcessor cannot is cast to Org.apache.AnnotationProcessor

Source: Internet
Author: User

These days to the company, the company's svn broken down, and then the project is relatively large, is a distributed, and then colleagues put the project sent me. I import the project in the MyEclipse, the corresponding jar package also built a personal library to import the project, now the project is not error, but when I deployed to Tomcat boot server, Access to the portal package was such a mistake: Java.lang.ClassCastException:org.apache.catalina.util.DefaultAnnotationProcessor cannot is cast to Org.apache.AnnotationProcessor


The above error means that the type conversion error. I was looking at this mistake should not be a code-level error, encountered this jar package conflict must be imported jar duplicate. Then go to Baidu under, online blog on the processing of this error is also quite a lot, here I summarize and organize.


The first reason for this error is that Tomcat's Lib folder jar package conflicts with the jar package under the project's Lib file. Tomcat has annotationprocessor interfaces in both Catalina.jar and Jasper.jar, so when it runs, it goes wrong: java.lang.ClassCastException: Org.apache.catalina.util.DefaultAnnotationProcessor. To check if this is the case, you can go through the build path of your project and see if the imported package is repeatedly imported into the Tomcat next Lib package. I went to see it myself, and really, that means that when the deployment project is under Tomcat, these packages are automatically placed in the path of our project, but we have these packages in our own project, which is equivalent to the 2 sides of these packages, so the jar packet conflicts and the above type conversion exception is reported.


There are 2 ways to solve this: 1, remove all duplicates of the project under the Lib file and the Tomcat jar. That is to put their own project inside the re-import Tomcat Lib under the package are removed, because I am a colleague directly to my project, there are many projects are Java projects, so my project if directly remove these packages the code will be error, so I took the 2nd way


2, modified the context.xml file in Tomcat, add <loader delegate= "true"/> under the context element, and now it's normal.
Baidu has the next loader element, about its interpretation is as follows, pay attention to the delegate this element is good.
Loader objects can appear in the context to control the loading of Java classes. Although you can change the Loadet class, it is not generally done, so in the following properties, we list the standard properties and the properties that are accepted by the "generic" ClassLoader.
Properties: ClassName, meaning: Org.apache.catalina.Loader implementation class name, default value: Org.apache.catalina.loader.WebappClassLoader
Properties: Delegate, meaning: True represents the use of the formal Java proxy pattern (the loader of the parent class is queried first); false means looking in the Web application first. Warning: If you do not know how to handle it, do not change this property value, default value: FALSE
Properties: Loaderclass, meaning: class loader, default value: Org.apache.catalina.loader.WebappClassLoader
attribute: reloadable, meaning: Same as the meaning under context. The value at this time overwrites the value in the context, the default value: FALSE
Properties: Workdir, meaning: The directory where temporary files are stored, default values: temporary directories under Catalina_base (Catalina_base if the set Catalina_tome value is not displayed)

Org.apache.catalina.util.DefaultAnnotationProcessor cannot is cast to Org.apache.AnnotationProcessor

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.