title: Injecting different beans depending on provided environment property
body: <p>So I have an application that can be started for several different countries for example:
  mvn clean package -Dcountry=FRANCE
  resp.
  mvn clean package -Dcountry=GERMANY</p>
  
  <p>For different countries I have different behavior especially when I'm validating stuff.</p>
  
  <p>So I have this class that contains a country dependent validator:</p>
  
  <pre><code>@Component
  public class SomeValidatingClass {
  
      private final Validator myCountrySpecificValidator;
  
      @Autowired
      public SomeValidatingClass(MyCountrySpecificValidator myCountrySpecificValidator) {
          this.myCountrySpecificValidator = myCountrySpecificValidator;
      }
  
      public void doValidate(Object target, Errors errors) {
          myCountrySpecificValidator.validate(target, errors);
      }
  }
  </code></pre>
  
  <p>The first country dependent validator:</p>
  
  <pre><code>public class MyCountrySpecificValidator1 implements Validator {
      @Override
      public void validate(Object target, Errors errors) {
          if (target == null) {
              errors.rejectValue("field", "some error code");
          }
      }
  }
  </code></pre>
  
  <p>The second country dependent validator:
  Let's assume for </p>
  
  <pre><code>public class MyCountrySpecificValidator2 implements Validator {
     @Override
     public void validate(Object target, Errors errors) {
         if (target != null) {
             errors.rejectValue("field", "some other error code");
         }
     }
  }
  </code></pre>
  
  <p>My question is</p>
  
  <ul>
  <li>how do I manage to inject an instance of <strong>MyCountrySpecificValidator1</strong> into <strong>SomeValidatingClass</strong> when the application was startet with <strong>"-Dcountry=FRANCE"</strong></li>
  </ul>
  
  <p>and resp.</p>
  
  <ul>
  <li>how do I manage to inject an instance of <strong>MyCountrySpecificValidator2</strong> into <strong>SomeValidatingClass</strong> when the application was startet with <strong>"-Dcountry=GERMANY"</strong></li>
  </ul>