title: How to properly exclude spring?
body: <p>I tested the code below in STS. When the POM is empty, I get</p>
  
  <blockquote>
    <p>java.lang.ClassNotFoundException: org.springframework.context.support.FileSystemXmlApplicationContext</p>
  </blockquote>
  
  <p>This is correct. However, when I add a dependency of my other project without spring framework, I can get the class <code>org.springframework.context.support.FileSystemXmlApplicationContext</code>. This is even when I put an exclusion of the  spring framework in POM. It is very strange.</p>
  
  <p>My question is that, when I put another project that is not related spring, why can I still get the spring context class? How should I exclude spring?</p>
  
  <pre class="lang-java prettyprint-override"><code>public class CustomerClassloader extends ClassLoader {
      public void findTheClass() {
           try {
              Class result = findSystemClass(
                "org.springframework.context.support.FileSystemXmlApplicationContext");
              System.out.println("result=" + result);
          } catch (ClassNotFoundException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
      }
  
      public static void main(String[] args) {
          CustomerClassloader loader = new CustomerClassloader();
          loader.findTheClass();
      }
  }
  </code></pre>
  
  <p>
  </p>
  
  <pre><code>&lt;project 
      xmlns="http://maven.apache.org/POM/4.0.0"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
          http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
  
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  
  
      &lt;artifactId&gt;iotex-test&lt;/artifactId&gt;
  
      &lt;parent&gt;
          &lt;groupId&gt;com.iotex.cloud&lt;/groupId&gt;
          &lt;artifactId&gt;iotex-cloud&lt;/artifactId&gt;
          &lt;version&gt;1.0.0-SNAPSHOT&lt;/version&gt;
          &lt;relativePath&gt;../iotex-cloud/pom.xml&lt;/relativePath&gt;
      &lt;/parent&gt;
  
      &lt;name&gt;iotex-test&lt;/name&gt;
      &lt;url&gt;http://maven.apache.org&lt;/url&gt;
  
      &lt;properties&gt;
          &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
      &lt;/properties&gt;
  
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.iotex.security&lt;/groupId&gt;
              &lt;artifactId&gt;iotex-security-util&lt;/artifactId&gt;
              &lt;version&gt;1.0.0-SNAPSHOT&lt;/version&gt;
              &lt;exclusions&gt;
                  &lt;exclusion&gt;  &lt;!-- declare the exclusion here --&gt;
                      &lt;groupId&gt;org.springframework&lt;/groupId&gt;
                      &lt;artifactId&gt;spring-context&lt;/artifactId&gt;
                  &lt;/exclusion&gt;
              &lt;/exclusions&gt; 
          &lt;/dependency&gt;
  
      &lt;/dependencies&gt;
  &lt;/project&gt;
  
  &lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
    &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  
  
      &lt;groupId&gt;com.iotex.cloud&lt;/groupId&gt;
      &lt;artifactId&gt;iotex-cloud&lt;/artifactId&gt;
      &lt;version&gt;1.0.0-SNAPSHOT&lt;/version&gt;
      &lt;name&gt;iotex-cloud&lt;/name&gt;
      &lt;packaging&gt;pom&lt;/packaging&gt;
  
      &lt;!-- 指定Maven仓库 --&gt;
      &lt;repositories&gt;
         &lt;repository&gt;
              &lt;id&gt;iotex&lt;/id&gt;
              &lt;name&gt;nexus Repository&lt;/name&gt;
              &lt;layout&gt;default&lt;/layout&gt;
              &lt;url&gt;http://localhost:7777/nexus/content/groups/public/&lt;/url&gt;
              &lt;releases&gt;
                  &lt;enabled&gt;true&lt;/enabled&gt;
              &lt;/releases&gt;
              &lt;snapshots&gt;
                  &lt;enabled&gt;true&lt;/enabled&gt;
              &lt;/snapshots&gt;
          &lt;/repository&gt; 
  
      &lt;/repositories&gt;
  
  
    &lt;distributionManagement&gt;
      &lt;snapshotRepository&gt;
          &lt;id&gt;iotex&lt;/id&gt;
          &lt;name&gt;iotex-snapshots&lt;/name&gt;
          &lt;url&gt;http://127.0.0.1:7777/nexus/content/repositories/snapshots/&lt;/url&gt;
      &lt;/snapshotRepository&gt;
  
      &lt;repository&gt;
          &lt;id&gt;iotex&lt;/id&gt;
          &lt;name&gt;iotex-releases&lt;/name&gt;
          &lt;url&gt;http://127.0.0.1:7777/nexus/content/repositories/releases/&lt;/url&gt;
      &lt;/repository&gt;
       &lt;!--
      &lt;site&gt;
          &lt;id&gt;module-site&lt;/id&gt;
          &lt;name&gt;openEjb-sit&lt;/name&gt;
          &lt;url&gt;file://D:/OpenEjb/apache-openejb-4.5.2/lib/&lt;/url&gt;
      &lt;/site&gt;
      --&gt;
     &lt;/distributionManagement&gt;
  
    &lt;properties&gt;
  
          &lt;!-- Generic properties --&gt;
          &lt;java.version&gt;1.7&lt;/java.version&gt;
          &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
          &lt;project.reporting.outputEncoding&gt;UTF-8&lt;/project.reporting.outputEncoding&gt;
  
          &lt;!-- Spring --&gt;
          &lt;spring-framework.version&gt;3.1.4.RELEASE&lt;/spring-framework.version&gt;
  
          &lt;!-- Hibernate / JPA --&gt;
          &lt;hibernate.version&gt;4.3.10.Final&lt;/hibernate.version&gt;
  
          &lt;!-- Logging --&gt;
          &lt;!-- Logging --&gt;
  
          &lt;logback.version&gt;1.1.1&lt;/logback.version&gt;
          &lt;slf4j.version&gt;1.7.6&lt;/slf4j.version&gt;
  
          &lt;!-- Test --&gt;
          &lt;junit.version&gt;4.11&lt;/junit.version&gt;
  
          &lt;commons-lang.version&gt;2.6&lt;/commons-lang.version&gt;
     &lt;/properties&gt;
  
      &lt;dependencyManagement&gt;
  
      &lt;dependencies&gt;
  
       &lt;/dependencies&gt;    
      &lt;/dependencyManagement&gt;
  
  
      &lt;modules&gt;
          &lt;module&gt;../iotex-test&lt;/module&gt;
      &lt;/modules&gt;
  &lt;/project&gt;
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/0793n.jpg" alt=""></p>