title: SpringBoot - Register Bean as Rest Controller
body: <p>I'm using Spring Boot AutoConfiguration for registering the beans. Need to find a way through which I can register the beans configured via Auto-Configuration as a Rest Controller</p>
  <p><code>SampleController.java</code></p>
  <pre class="lang-java prettyprint-override"><code>public class SampleController
  {
      @GetMapping(&quot;/sample-path&quot;)
      public String sampleMethod()
      {
          return &quot;Sample String&quot;;
      }
  }
  </code></pre>
  <p><code>SampleControllerAutoConfiguration.java</code></p>
  <pre class="lang-java prettyprint-override"><code>@Configuration
  @ConditionalOnProperty(value = &quot;some.property&quot;, havingValue = &quot;true&quot;) // using this property, the parent app may or may not chose to have the Controller Endpoint
  public class SampleControllerAutoConfiguration
  {
      // Need to register this bean as a controller
      @Bean
      @ConditionalOnMissingBean
      public SampleController sampleController()
      {
          return new SampleController();
      }
  }
  </code></pre>
  <p>I can't annotate <code>SampleController</code> with <code>@RestController</code> since it's in the same package as the parent project which imports this and hence get's auto-configured due to Component-Scan</p>