title: Start spring-boot application with classLoader
body: <p>I'm searched a lot for a solution for my case, basically i will start/run my spring boot application in other spring boot application.</p>
  
  <p>How i tried do:</p>
  
  <pre class="lang-java prettyprint-override"><code>String[] args = { "-Dspring.profiles.active=development",
                  "-Dspring.config.location=config/example-db-development.properties,config/example-custom-development.properties",
                  "-Dloader.path=test/lib" };
  
  File fatJar = new File("D:/spring-boot-example/test/spring-boot-example-api.jar");
  
  ClassLoader classLoader = new URLClassLoader(new URL[] { fatJar.toURI().toURL() });
  
  Class&lt;?&gt; mainClass = classLoader.loadClass(getMainClassName(fatJar));
  Method mainMethod = mainClass.getMethod("main", String[].class);
  mainMethod.invoke(null, new Object[] { args });
  </code></pre>
  
  <pre class="lang-java prettyprint-override"><code>private static String getMainClassName(File fatJar) throws IOException {
          try (JarFile jarFile = new JarFile(fatJar)) {
              return jarFile.getManifest().getMainAttributes().getValue(Attributes.Name.MAIN_CLASS);
          }
      }
  </code></pre>
  
  <p>This started the example project, however, I need to add some dependencies of the example project to the project that should start the same. 
  And I'm still having problems for springboot to be able to create beans, for example:</p>
  
  <pre class="lang-java prettyprint-override"><code>org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'vendaPDVControllerImpl' defined in URL [jar:file:/D:/dsv-git/dsv-java/pdv-prototipos/spring-boot-integrador-testes/test/spring-boot-integrador-api.jar!/BOOT-INF/classes!/br/com/sysmo/integrador/api/impl/VendaPDVControllerImpl.class]: Post-processing of merged bean definition failed; nested exception is java.lang.IllegalStateException: Failed to introspect Class [br.com.sysmo.integrador.api.impl.VendaPDVControllerImpl] from ClassLoader [org.springframework.boot.loader.LaunchedURLClassLoader@31f924f5]
  </code></pre>
  
  <p>I do not want to have to add dependencies of the sample project on the project that should start it, and I already looked in the stack overflow for solutions, but found none that solves my problem.</p>
  
  <p>I'd like something like this, but from the classLoader, or another solution that makes it possible to start my application without adding its dependencies to my project:</p>
  
  <pre><code>java -jar -Dspring.profiles.active=development -Dspring.config.location=config/example-db-development.properties,config/example-custom-development.properties -Dloader.path=lib example-api-1.00.00.000.jar
  </code></pre>