title: Converting a regular Maven project to a Spring Boot project
body: <p>My supervisor asked me to convert an old Maven project we have lying around into a Spring Boot project such that we are able to access the project's backend via RESTful interaction (before that the project's backend was only accessible via a console interface).</p>
  
  <p>So, first I added a simple Spring Boot application in a separate package of project. After that I began to extend the pom.xml of the project by the dependencies needed for Spring Boot and adjusted the overall project setup. Now, I tried to run the backend of the old project, which turned out to be working. However, the simple Spring Boot application did not.</p>
  
  <p>I narrowed down the problem to a conflicting dependency in the "old" part of the pom.xml:</p>
  
  <pre><code>&lt;dependency&gt;
          &lt;groupId&gt;org.apache.logging.log4j&lt;/groupId&gt;
          &lt;artifactId&gt;log4j-api&lt;/artifactId&gt;
          &lt;version&gt;2.6.1&lt;/version&gt;
  &lt;/dependency&gt;
  </code></pre>
  
  <p>When I leave this dependency in the pom.xml the old backend works, but the Spring Boot application fails with the following error:</p>
  
  <pre><code>WARN: Cannot find template location: classpath:/templates/ (please add some templates or check your Thymeleaf configuration)
  </code></pre>
  
  <p>If I comment this dependency out the Spring Application works completely fine, but the old backend fails. I use the version <code>2.0.4.RELEASE</code> of <code>spring-boot-admin-starter-server</code>. I think that the old backend's version of the logging package is different from the one included in <code>spring-boot-admin-starter-server</code>. However, I somehow need both versions in my project.</p>
  
  <p>What's not possible:</p>
  
  <ul>
  <li>Updating the old sources, since some of them have a coyright of an
  external company</li>
  </ul>
  
  <p>What I already tried, but I wasn't successful with:</p>
  
  <ul>
  <li>Exclude the logging from then Spring Boot depedencies. This results in the following error:</li>
  </ul>
  
  <p><code>SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
  SLF4J: Defaulting to no-operation (NOP) logger implementation
  SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.</code></p>
  
  <ul>
  <li>I also to tried to work with the shade plugin as some suggested from my web research. Unfortunately, I was not able to solve the problem with this approach.</li>
  </ul>
  
  <p>Does anyone have suggestions how to solve this problem? I would be very grateful. I am not used to solve dependency problems of this kind. Please excuse me, if I am missing something obvious.</p>
  
  <p>-lema</p>
  
  <blockquote>
    <p>EDIT pom.xml (unfortunately I had to leave out bigger parts of it) :</p>
  </blockquote>
  
  <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;packaging&gt;jar&lt;/packaging&gt;
  &lt;description&gt;&lt;/description&gt;
  
  &lt;properties&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;java.version&gt;1.8&lt;/java.version&gt;
      &lt;spring-boot-admin.version&gt;2.0.2&lt;/spring-boot-admin.version&gt;
      &lt;spring-boot-dependencies.version&gt;2.0.4.RELEASE&lt;/spring-boot-dependencies.version&gt;
  
      ...
  
      &lt;rat.skip&gt;true&lt;/rat.skip&gt;
      &lt;log4j-version&gt;2.6.1&lt;/log4j-version&gt;
  &lt;/properties&gt;
  
  &lt;repositories&gt;
      ...
  &lt;/repositories&gt;
  
  &lt;dependencyManagement&gt;
      &lt;dependencies&gt;
          &lt;!-- Necessary dependency for running Spring Boot without starter parent --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.data&lt;/groupId&gt;
              &lt;artifactId&gt;spring-data-releasetrain&lt;/artifactId&gt;
              &lt;version&gt;Fowler-SR2&lt;/version&gt;
              &lt;type&gt;pom&lt;/type&gt;
              &lt;scope&gt;import&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-dependencies&lt;/artifactId&gt;
              &lt;version&gt;${spring-boot-dependencies.version}&lt;/version&gt;
              &lt;type&gt;pom&lt;/type&gt;
              &lt;scope&gt;import&lt;/scope&gt;
          &lt;/dependency&gt;
  
          ...
  
      &lt;/dependencies&gt;
  &lt;/dependencyManagement&gt;
  &lt;dependencies&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;de.codecentric&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-admin-starter-server&lt;/artifactId&gt;
          &lt;version&gt;${spring-boot-admin.version}&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
          &lt;scope&gt;test&lt;/scope&gt;
      &lt;/dependency&gt;
  
      ...
  
      &lt;!-- TODO The version of this dependency lets Spring Boot fail, but is 
          necessary tu run the old backend --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.apache.logging.log4j&lt;/groupId&gt;
          &lt;artifactId&gt;log4j-api&lt;/artifactId&gt;
          &lt;version&gt;${log4j-version}&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.apache.logging.log4j&lt;/groupId&gt;
          &lt;artifactId&gt;log4j-core&lt;/artifactId&gt;
          &lt;version&gt;${log4j-version}&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.apache.logging.log4j&lt;/groupId&gt;
          &lt;artifactId&gt;log4j-iostreams&lt;/artifactId&gt;
          &lt;version&gt;${log4j-version}&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.apache.logging.log4j&lt;/groupId&gt;
          &lt;artifactId&gt;log4j-1.2-api&lt;/artifactId&gt;
          &lt;version&gt;${log4j-version}&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.apache.logging.log4j&lt;/groupId&gt;
          &lt;artifactId&gt;log4j-jcl&lt;/artifactId&gt;
          &lt;version&gt;${log4j-version}&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.apache.logging.log4j&lt;/groupId&gt;
          &lt;artifactId&gt;log4j-jul&lt;/artifactId&gt;
          &lt;version&gt;${log4j-version}&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.fusesource.jansi&lt;/groupId&gt;
          &lt;artifactId&gt;jansi&lt;/artifactId&gt;
          &lt;version&gt;1.13&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;com.google.code.gson&lt;/groupId&gt;
          &lt;artifactId&gt;gson&lt;/artifactId&gt;
      &lt;/dependency&gt;
  
      ...
  
  &lt;/dependencies&gt;
  &lt;build&gt;
      &lt;defaultGoal&gt;verify&lt;/defaultGoal&gt;
      &lt;plugins&gt;
          &lt;plugin&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
          &lt;/plugin&gt;
          &lt;plugin&gt;
              ...
          &lt;/plugin&gt;
  
  
          &lt;plugin&gt;
              &lt;artifactId&gt;maven-assembly-plugin&lt;/artifactId&gt;
              &lt;version&gt;2.6&lt;/version&gt;
              &lt;executions&gt;
                  &lt;execution&gt;
                      &lt;id&gt;prepare-config-zip&lt;/id&gt;
                      &lt;phase&gt;prepare-package&lt;/phase&gt;
                      &lt;goals&gt;
                          &lt;goal&gt;single&lt;/goal&gt;
                      &lt;/goals&gt;
                      &lt;configuration&gt;
                          &lt;descriptors&gt;
                              &lt;descriptor&gt;${basedir}/src/main/assembly/config.xml&lt;/descriptor&gt;
                          &lt;/descriptors&gt;
                          &lt;finalName&gt;configs&lt;/finalName&gt;
                          &lt;appendAssemblyId&gt;false&lt;/appendAssemblyId&gt;
                      &lt;/configuration&gt;
                  &lt;/execution&gt;
                  &lt;execution&gt;
                      &lt;id&gt;prepare-dist-zip&lt;/id&gt;
                      &lt;phase&gt;package&lt;/phase&gt;
                      &lt;goals&gt;
                          &lt;goal&gt;single&lt;/goal&gt;
                      &lt;/goals&gt;
                      &lt;configuration&gt;
                          &lt;descriptor&gt;src/main/assembly/dist.xml&lt;/descriptor&gt;
                          &lt;finalName&gt;...&lt;/finalName&gt;
                          &lt;appendAssemblyId&gt;false&lt;/appendAssemblyId&gt;
                      &lt;/configuration&gt;
                  &lt;/execution&gt;
              &lt;/executions&gt;
          &lt;/plugin&gt;
  
          &lt;plugin&gt;
              &lt;artifactId&gt;maven-enforcer-plugin&lt;/artifactId&gt;
              &lt;configuration&gt;
                  &lt;rules&gt;
                      &lt;requireJavaVersion&gt;
                          &lt;version&gt;1.8&lt;/version&gt;
                      &lt;/requireJavaVersion&gt;
                  &lt;/rules&gt;
              &lt;/configuration&gt;
          &lt;/plugin&gt;
  
      &lt;/plugins&gt;
  &lt;/build&gt;
  &lt;profiles&gt;
      &lt;profile&gt;
          &lt;id&gt;attach-standalone&lt;/id&gt;
          &lt;build&gt;
              &lt;plugins&gt;
                  &lt;plugin&gt;
                      &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                      &lt;artifactId&gt;maven-shade-plugin&lt;/artifactId&gt;
                      &lt;configuration&gt;
                          &lt;shadedArtifactAttached&gt;true&lt;/shadedArtifactAttached&gt;
                          &lt;shadedClassifierName&gt;standalone&lt;/shadedClassifierName&gt;
                      &lt;/configuration&gt;
                  &lt;/plugin&gt;
              &lt;/plugins&gt;
          &lt;/build&gt;
      &lt;/profile&gt;
      &lt;profile&gt;
          &lt;id&gt;dont-attach-standalone&lt;/id&gt;
          &lt;activation&gt;
              &lt;activeByDefault&gt;true&lt;/activeByDefault&gt;
          &lt;/activation&gt;
          &lt;build&gt;
              &lt;plugins&gt;
                  &lt;plugin&gt;
                      &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                      &lt;artifactId&gt;maven-shade-plugin&lt;/artifactId&gt;
                      &lt;configuration&gt;
                          &lt;!-- Prevent huge shaded artifacts from being deployed to Artifactory --&gt;
                          &lt;outputFile&gt;...&lt;/outputFile&gt;
                      &lt;/configuration&gt;
                  &lt;/plugin&gt;
              &lt;/plugins&gt;
          &lt;/build&gt;
      &lt;/profile&gt;
  &lt;/profiles&gt;
  </code></pre>
  
  <p></p>
  
  <blockquote>
    <p>EDIT: I just found out that if you remove the version element inside of the conflicting dependency the Spring Boot Application works, but unfortunately the backend then fails.</p>
  </blockquote>