2

Is there a way to avoid putting a string in the Qualifier annotation to specify which implementation to take by the Spring container? I personnaly dislike magic string. If your project is big and you refactor stuff, you will have to fix the strings everywhere. Is there a more elegant way of doing it?

Rushino
  • 9,225
  • 14
  • 51
  • 92

1 Answers1

1

You could reference a constant: https://stackoverflow.com/a/16477693/1777072

Or read from a properties file: https://stackoverflow.com/a/12715752/1777072

But, ultimately, these still work from hardcoded strings: just at different levels.

Personally, I'd stick with having it hardcoded in the class - rather than having to hunt through a properties file, or change a constant. After all, that's the class that specifically wants that exact implementation; so that's the clearest place to put the hardcoding.

David Lavender
  • 7,362
  • 3
  • 34
  • 52