Rushino
Rushino

Reputation: 9505

Is there a way to avoid putting a string in the Qualifier annotation?

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?

Upvotes: 2

Views: 589

Answers (1)

David Lavender
David Lavender

Reputation: 8331

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.

Upvotes: 1

Related Questions