How do I dynamically assign enum values using java spring bean -


i've got following code:

package vb4.email;  import org.springframework.beans.factory.annotation.value;  public enum validaddresses {      // todo: there cleaner way switch debugs?     // how make bean-able?      @value("${email.addresses.defaults.support}")     default_support_address("support@example.com"),     @value("${email.addresses.defaults.performance}")     default_performance_support_address("speed@example.com");      private final string email;      private validaddresses(final string email){         this.email = email;     }      @override     public string tostring()     {         return this.email;     } } 

as can see @value annotations, i'm looking "beanify" process. want benefits of enumerable construct, i'd make configurable in our .properties file. please keep in mind .properties file has key=value pairs used extensively throughout site.

please keep answers on mark; i'm not looking debate validity of in place. (trust me understand frustration).

you can provide setters validaddresses enum , use initializer, smth like

@configurable public class enumvalueinitializer {    @value("${email.addresses.defaults.support}")   private string support;    @postconstruct   public void postconstruct() {     initializeaddressesenum();   }    private void initializeaddressesenum() {     validaddresses.default_support_address.setemail(support);   }  } 

i hope helpful. luck.


Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -