Is the Java Class delegation model mandatory?

If I have a custom class loader that, instead of delegating to its parent, is trying to search and load the class itself, will this violate any stated / undefined rule?

+3
source share
1 answer

Tomcat classloader classloader follows this model, so I think it works, at least to some extent :) From the documentation of the Tomcat class loader :

As mentioned above, the web application class loader diverges from the default Java 2 delegation model (as recommended in the servlet specification, version 2.4, section 9.7.2 “Web application loader class”). When a request to load a class from the WebappX class loader of a Web application is processed, this class loader will first search in local repositories, and not delegate it before searching. There are exceptions. Classes that are part of JRE base classes cannot be overestimated. For some classes (such as XML parser components in J2SE 1.4+), you can use J2SE 1.4. Finally, any JAR file containing Servlet API classes will be explicitly ignored by the class loader. Do not include such JAR files in your web application. All other class loaders in Tomcat 6 follow the usual delegation pattern.

, , , , . ( ) , /, .

+3

All Articles