title: how to get application property from ConditionContext
body: <p>I am working on spring but not spring boot. I have a class marked as <code>@Component</code> (but not as <code>@Configuration</code> [it's not config class]). I would like to create it based on the <code>serviceA.create</code> property in <code>app.properties</code>. It the file it looks like this: <code>serviceA.create=true</code>. I would think, that in the code it narrows down to:</p>
  
  <pre><code>@Override
      public boolean matches(final ConditionContext context, final AnnotatedTypeMetadata metadata) {
  
          return Boolean.valueOf(context.getEnvironment().getProperty("serviceA.create"));
      }
  </code></pre>
  
  <p>But based on different questions/answers (f.e. <a href="https://stackoverflow.com/questions/32790111/spring-condition-not-able-to-read-value-from-property-file">this</a>) on the same topic, it sounds like adding <code>@PropertySource(value="classpath:config.properties")</code> is mandatory for this to work (to actually read the property value). </p>
  
  <p>Question is, if I am able to get property from <code>ConditionContext</code> without defining <code>@PropertySource</code> ? because currently I am getting <code>null</code> without that annotation.</p>
  
  <hr>
  
  <p>It should be done in the following way:</p>
  
  <pre><code>@Component
  @Conditional(ServiceACondition.class)
  @PropertySource(value="classpath:app.properties")
  public class ServiceA {
  (...)
  }
  </code></pre>
  
  <p>and the cond. class</p>
  
  <pre><code>public class ServiceACondition implements Condition {
      @Override
      public boolean matches(final ConditionContext context, final AnnotatedTypeMetadata metadata) {
  
          return Boolean.valueOf(context.getEnvironment().getProperty("serviceA.start"));
      }
  }
  </code></pre>