title: How to validate annotated with Spring @Value field using custom annotation?
body: <p>How can i check if "${path}" value is not empty or is correct path and if so, throw some exception? I want to it happen during Bean creation. 
  All I found that is such validation used in multilayer
  apps for user input data validation in @Controller classes with using @Valid annotation.
  But what i did was not working.</p>
  
  <p>It a simple Spring app, that reading application.properties and somehow processes them.
  Here is my code:</p>
  
  <pre><code>@Component
  public class ParseService {
  
  @Value("${path}")
  @PathValue
  private String path;
  }
  
  @Documented
  @Constraint(validatedBy = PathValidatorImpl.class)
  @Retention(RUNTIME)
  @Target({ElementType.FIELD})
  public @interface PathValue {
  
    String message() default "Is empty or not valid path!"; 
  }
  
  public class PathValidatorImpl implements ConstraintValidator&lt;PathValue, 
  String&gt; {
  
    @Override
    public void initialize(PathValue pathValue) {
    }
  
    @Override
    public boolean isValid(String path, ConstraintValidatorContext ctx) {
    if (path.isEmpty() || !(new File(path).exists())) {
       return false;
      } else
       return true;
      }
   }
  </code></pre>
  
  <p>Can I do this and if so, What am I doing wrong?</p>
  
  <p>I tried this:</p>
  
  <pre><code>@Component
  public class FileGuider {
  public List&lt;File&gt; search(@Valid String path, String sourceFileExtension)
    throws IOException, NoFilesToParseException {...}
  </code></pre>
  
  <p>P.S. I use Spring in this app for studying.</p>