title: How can I load configuration properties to annotation arguments?
body: <p>I have a class which is annotated with <code>@Entry</code>. This annotation accepts two arguments, <code>base</code> and <code>objectClasses</code>. I want to load these two arguments from a static configuration file, <code>application.yaml</code>.</p>
  
  <p>This is the class, <code>src/main/com.my.package/User/User.java</code>:</p>
  
  <pre><code>import org.springframework.ldap.odm.annotations.Attribute;
  import org.springframework.ldap.odm.annotations.Entry;
  import org.springframework.ldap.odm.annotations.Id;
  
  import javax.naming.Name;
  
  
  @Entry(base = "${ldap.organizationalUnitString}" , objectClasses = "${ldap.objectClass}")
  public class User {
  
      @Id
      private Name id;
  
      private @Attribute(name = "cn") String username;
      private @Attribute(name = "sn") String password;
  
      //Getters and setters
  
  }
  </code></pre>
  
  <p>This is my configuration file, <code>src/resources/application.yaml</code>:</p>
  
  <pre><code>ldap:
    partitionSuffix: myPartitionSuffix
    partition: myPartition
    principal: "my Principal"
    password: myPassword
    url: ldap://myURL.url
    organizationalUnitString: "my OU"     
    objectClass: User
  </code></pre>
  
  <p>The way it's currently written, I get a runtime exception </p>
  
  <blockquote>
    <p>org.springframework.ldap.InvalidNameException: Invalid name:
    ${ldap.organizationalUnitString};</p>
  </blockquote>
  
  <p>I have tried this, <a href="https://stackoverflow.com/a/38125875/4640960">https://stackoverflow.com/a/38125875/4640960</a>, using the <code>@Value</code> annotation, but I'm stuck with the compile time error </p>
  
  <blockquote>
    <p>Type mismatch: cannot convert from Value to String</p>
  </blockquote>
  
  <p>Is there some way to achieve what I'm trying to? I know that it's possible with a <code>public static final</code> variable, looking like this:</p>
  
  <pre><code>import org.springframework.ldap.odm.annotations.Attribute;
  import org.springframework.ldap.odm.annotations.Entry;
  import org.springframework.ldap.odm.annotations.Id;
  
  import javax.naming.Name;
  
  import static com.my.package.User.User.base;
  import static com.my.package.User.User.objectClass;
  
  
  @Entry(base = base , objectClasses = objectClass)
  public class User {
  
      public static final String base = "my OU";
      public static final String objectClass = "User";
  
      @Id
      private Name id;
  
      private @Attribute(name = "cn") String username;
      private @Attribute(name = "sn") String password;
  
      //Getters and setters
  }
  </code></pre>
  
  <p>But I'd rather not hardcode the parameters inside the class.</p>
  
  <p>Several other questions ask about passing non-static variables as annotation arguments, which I know is not possible, but my question is slightly different. I only want to pass a static configuration property.</p>