I’m looking for some best practices when using Spring 3 annotations.
I’m currently moving to Spring 3 and from what I’ve read so far I see a lot of accent placed on using annotations and moving away from XML configuration.
Actually what is recommended is a mix of both styles, with annotations covering things that won’t change often or from one run to the next (e.g. a @Controller will remain like that for the life time of the application), while the things that change and must be configurable go into XML (e.g. a mail smtp address, endpoints for web services that your application talks to etc).
My question is what should go into annotations and to what extent?
At which point annotations make things harder instead of easier? Is the technology (Spring 3) fully adopted as to be able to make such statements or does it take some more time for people to gain experience with it and then reflect on the issue?
It is always difficult to get real advanced information.
The easy tutorial with “look on my blog, I copied the hello word tutorial from Spring Source website… Now you can put fancy annotations everywhere, it the solution of all of our problems including cancer and starvation.” is not really usefull.
If you remember right spring core had several purposes, among them:
implementation/configuration of a
bean at any time
place to put your configuration
Anotation fail for all theses needs:
(you can use standard anotation only
but as soon as you have at least one
spring anotation this is no longer
true)
recompile to change bean
implementation or configuration
code. It can be difficult to find
what bean will be really used just by
reading the code or XML configuration
file.
In fact we have shifted our focus:
provide several implementations of
our services.
an API is not that bad.
for real dependancy injection
anymore, but mainly to increase
productivity and reduce java code
verbosity.
So I would use anotations when it make sence. When it is purerly to remove boilerplate code, verbosity. I would take care of using the XML configuration file for thing that you want to make configurable, even if it is only to provide a stub implementation of the service in unit tests.