title: How to make simple property validation when using Spring @Value
body: <p>How can I check, if <code>${service.property}</code> is not an empty string and if so, throw some kind of readable exception? It must happen during Bean creation.</p>
  
  <pre><code>@Component
  public class Service {
  
    @Value("${service.property}")
    private String property;
  }
  </code></pre>
  
  <p>I am looking for the <strong>easiest</strong> way (least written code). Would be great if by using annotations.</p>
  
  <p>My current solution is to perform "handwritten" validation inside setter for the property, but is a little too much code for such easy thing.</p>
  
  <p>Hint: I looked for some way to use the SpEL, since I use it already inside <code>@Value</code>, but as far I have found out, it would not be that easy/clean. But could have overlooked something.</p>
  
  <p>Clarification: Expected behaviour is, that the application will <strong>not</strong> start up. The goal is to assure, that all properties are set, and especially, that <strong>string properties are not empty</strong>. Error should say clearily, what is missing. I don't want to set any defaults! User must set it all.</p>