Cannot is cast to javax.servlet.Filter error, cause Servlet-api.jar conflict

Source: Internet
Author: User

Use MAVEN to develop a Web application that starts with an error:

class: Javax/servlet/servlet. class

Then output the error:

Severity: Exception starting filter EncodingFilterjava.lang.ClassCastException: Org.springframework.web.filter.CharacterEncodingFilter cannot is cast to Javax.servlet.Filter

The cause of the problem is that the server-:tomcat starts to read all the jar packages in the Tomcat/lib directory into memory and fails to load if the same package is in the Web-inf/lib directory of the application in the WebApps directory.

Similar problems can occur between different versions of packages

The solution to this problem is to use the <scope> tag for Servlet-ap.jar, compile with Servlet-api and JSP-API, but not both when packaging.

As follows:

<Dependency>    <groupId>Javax.servlet</groupId>    <Artifactid>Servlet-api</Artifactid>    <version>2.4</version>    <Scope>Provided</Scope></Dependency>

<dependency> <scope> It primarily manages dependent deployments. Currently <scope> can use 5 values:
* Compile, default, applies to all stages and will be published along with the project.
* provided, similar to compile, expects the JDK, container or user to provide this dependency. such as Servlet.jar.
* Runtime, used only at runtime, such as JDBC driver, for run and test phases.
* Test, used only during testing, to compile and run the test code. Will not be published with the project.
* System, similar to provided, needs to explicitly provide an jar,maven that contains dependencies and does not find it in repository.

Cannot is cast to javax.servlet.Filter error, cause Servlet-api.jar conflict

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.