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?
Asked
Active
Viewed 382 times
2
-
see the solution here: https://stackoverflow.com/q/69263925/13822943 – 11_22_33 Sep 21 '21 at 08:37
1 Answers
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
- 8,021
- 3
- 35
- 55