How to change java.lang.ClassLoader order in Tomcat : Context initialization failed

### Symptom

**the class loader (instance of java/net/URLClassLoader) for the method's defining class have different Class objects for the type used in the signature**

```
[ERROR] 2018-01-24 12:57:44,394 [http-apr-8080-exec-8] org.springframework.web.servlet.DispatcherServlet:497 - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'documentationController' defined in ServletContext resource [/WEB-INF/spring/rest-servlet.xml]: Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.jsondoc.springmvc.controller.JSONDocController]: Constructor threw exception; nested exception is java.lang.LinkageError: loader constraint violation: when resolving method "org.slf4j.impl.StaticLoggerBinder.getLoggerFactory()Lorg/slf4j/ILoggerFactory;" the class loader (instance of org/apache/catalina/loader/ParallelWebappClassLoader) of the current class, org/slf4j/LoggerFactory, and the class loader (instance of java/net/URLClassLoader) for the method's defining class, org/slf4j/impl/StaticLoggerBinder, have different Class objects for the type org/slf4j/ILoggerFactory used in the signature
        at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:275)
 ```



### How to fix

 - add **\<Loader delegate="true"/\>** to **$(catalina.base)/conf/context.xml**

 - before

```$(catalina.base)/conf/context.xml
<Context>

    <!-- Default set of monitored resources -->
    <WatchedResource>WEB-INF/web.xml</WatchedResource>

    <!-- Uncomment this to disable session persistence across Tomcat restarts -->
    <!--
    <Manager pathname="" />
    -->

    <Manager className="org.redisson.tomcat.RedissonSessionManager"
                 configPath="${catalina.base}/redisson.conf" readMode="MEMORY"/>

    <!-- Uncomment this to enable Comet connection tacking (provides events
         on session expiration as well as webapp lifecycle) -->
    <!--
    <Valve className="org.apache.catalina.valves.CometConnectionManagerValve" />
    -->

</Context>
```

 - after

```$(catalina.base)/conf/context.xml
<Context>

    <!-- Default set of monitored resources -->
    <WatchedResource>WEB-INF/web.xml</WatchedResource>

    <!-- Uncomment this to disable session persistence across Tomcat restarts -->
    <!--
    <Manager pathname="" />
    -->

    <Loader delegate="true"/>
    <Manager className="org.redisson.tomcat.RedissonSessionManager"
                 configPath="${catalina.base}/redisson.conf" readMode="MEMORY"/>

    <!-- Uncomment this to enable Comet connection tacking (provides events
         on session expiration as well as webapp lifecycle) -->
    <!--
    <Valve className="org.apache.catalina.valves.CometConnectionManagerValve" />
    -->

</Context>
```



### References

https://tomcat.apache.org/tomcat-8.5-doc/class-loader-howto.html

from the perspective of a web application, class or resource loading looks in the following repositories, in this order:

    Bootstrap classes of your JVM
    /WEB-INF/classes of your web application
    /WEB-INF/lib/*.jar of your web application
    System class loader classes (described above)
    Common class loader classes (described above)

If the web application class loader is configured with <Loader delegate="true"/> then the order becomes:

    Bootstrap classes of your JVM
    System class loader classes (described above)
    Common class loader classes (described above)
    /WEB-INF/classes of your web application
    /WEB-INF/lib/*.jar of your web application