0

In a Spring bean, I need to process a configuration property before using is, e.g.:

@Component
class UsersController {

  @Value("${roles}")
  private String rolesAsString;

  private List<String> roles;

  @PostConstruct
  public void initRoles() { 
    // just an example, not necessarily string splitting
    roles = rolesAsString.split(",");
  }

This works, but I am left with an unneeded member variable 'rolesString'. What would be a clean concise way to only keep the processed value?

Assen Kolov
  • 4,143
  • 2
  • 22
  • 32
  • 1
    [check this post](http://stackoverflow.com/a/12580260/1599937) – Aliaksei Bulhak May 11 '16 at 16:19
  • Thank you for your responses. I should have been more specific that I mean any preprocessing, as mentioned in the title, and not just splitting a string, as in the example. I will add a comment in the initRoles method to reflect that. The answer provided by Essex Boy is the answer from the link already provided by Aleksei. – Assen Kolov May 11 '16 at 19:00

1 Answers1

1

Properties is

roles=role1,role2,role3

Code is :

@Value("#{'${roles}'.split(',')}") 
private List<String> roles;
Essex Boy
  • 7,565
  • 2
  • 21
  • 24