title: Multiple Spring Boot application classes with profiles
body: <p>I have the requirement to be able to run my Spring Boot within a container environment, and as a standalone fat JAR. In the former mode, the application needs to register itself with Consul as this is used for service discovery, whereas in the later we need to disable this integration completely.</p>
  
  <p>To accomplish this I created 2 Application classes: (I actually used an abstract parent here for the duplicate annotations, but I'm omitting this for brevity)</p>
  
  <pre><code>@SpringBootApplication
  @EnableDiscoveryClient
  @EnableConfigurationProperties
  @Profile("!standalone")
  public class Application extends SpringApplication {
  
      ...
  
  }
  </code></pre>
  
  <p>and</p>
  
  <pre><code>@SpringBootApplication(exclude = {
      ConsulAutoConfiguration.class, ConsulBusAutoConfiguration.class })
  @EnableConfigurationProperties
  @Profile("standalone")
  public class ApplicationStandalone extends SpringApplication {
  
      ...
  
  }
  </code></pre>
  
  <p>Notice the use of profiles and that the standalone version excludes the auto configuration classes for Consul.</p>
  
  <p>When I try to build the JAR via Maven I get the following error:</p>
  
  <pre><code>[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:1.3.0.M5:repackage (default) on project mio-lmpp-service: Execution default of goal org.springframework.boot:spring-boot-maven-plugin:1.3.0.M5:repackage failed: Unable to find a single main class from the following candidates [tv.nativ.mio.lmpp.ApplicationConfig, tv.nativ.mio.lmpp.ApplicationConfigStandalone] -&gt; [Help 1]
  </code></pre>
  
  <p>What's the best way round this?</p>
  
  <p>Thanks</p>
  
  <p>Nick</p>