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