title: Migrating to @ConfigurationProperties with naming conflicts
body: <p>I have a Spring Boot application with an <code>application.properties</code> file that looks like this:</p>
  
  <pre><code>setting.mode = a # Can be either `a` or `b`
  setting.mode.a.subsetting1 = abc
  setting.mode.a.subsetting2 = def
  setting.mode.b.subsetting1 = ghi
  setting.mode.b.subsetting2 = jkl
  </code></pre>
  
  <p>We used to use <code>@Value</code> annotations to read these values, so it didn't matter that the name of the String <code>setting.mode</code> is the same as the prefix of the "sub-settings".</p>
  
  <p>I was given the task of cleaning up this application, and I want to move to using <code>@ConfigurationProperties</code> with a large configuration object that matches the content of the properties file in order to make the code easier to work with.</p>
  
  <p>I was thinking that the structure of the configuration class would look something like this (Kotlin example, but it doesn't matter):</p>
  
  <pre><code>@Component
  @ConfigurationProperties("setting")
  class MyProperties {
  
      // Has the value either `a` or `b` to tell us which component to use
      lateinit var mode: String
  
      // THE PROBLEM IS HERE
      // -------------------
      //
      // The two classes below need to be under the `mode`
      // prefix, but they can't be because it is already used
      // to get its String value above.
  
      val a = A()
  
      val b = B()
  
      class A {
          lateinit var subsetting1: String
          lateinit var subsetting2: String
      }
  
      class B {
          lateinit var subsetting1: String
          lateinit var subsetting2: String
      }
  }
  </code></pre>
  
  <hr>
  
  <p>Note that the value of <code>setting.mode</code> is also used to decide which bean to register:</p>
  
  <pre><code>@Bean
  @ConditionalOnProperty(name = ["setting.mode"], havingValue = "a")
  fun a(properties: MyProperties): CommonInterface {
      return A(properties.mode.a)
  }
  
  @Bean
  @ConditionalOnProperty(name = ["setting.mode"], havingValue = "b")
  fun b(properties: MyProperties): CommonInterface {
      return B(properties.mode.b)
  }
  </code></pre>
  
  <hr>
  
  <p>How can I set up this configuration (without having to rewrite the <code>application.properties</code> to remove the naming issue for all instances of this application)?</p>