This forum is now a read-only archive. All commenting, posting, registration services have been turned off. Those needing community support and/or wanting to ask questions should refer to the Tag/Forum map, and to http://spring.io/questions for a curated list of stackoverflow tags that Pivotal engineers, and the community, monitor.

Actually we are using more than one context file. So, we have classified our context files depending on the purpose: main-context.xml, datasources-context.xml, scheduled-tasks-context.xml, functionality1-context.xml, functionality2-context.xml…

Also we have our own context-loader for junit integration tests. Our context loader can load all these context files lazily; and allows us to refine/extend bean declarations in our test context files (test1-context.xml, …)

Thus, when we start our application in our production environment all the beans are loaded during the bootstrap (it takes two minutes). But, on the other hand, every time that we run a test, only the beans related to the test are being loaded in order to run it fastest.

At this point, we have several questions about the benefits that annotations could give us.

So, I’ll make a list of advantages for each possibility.

XML Declaration advantages
-----------------------------------

- I can read in one file how the beans are connected. (Similar to uml object diagram)

- I can edit a context file in the production environment without the necessity of redeploy in order to switch a conection between beans.

For example, if my SearchService is using my new FastCategoryService, and the new service fails, I can configure it editing the search-context.xml file to connect SearchService to my BDCategoryService implementation.

If I were to use annotations, I would have to recompile SearchService to connect it to the old BDCategoryService implementation.

- I can reuse my context files in the integration tests (lazily)

Annotation advantages
---------------------------

- Faster to develop.

- No need to organize the context files.

- I believe that STS can show to you how the beans are connected like an object diagram. Does this feature really exist?.

Have I forgotten any advantages or disadvantages? Please, different points of view are welcome.

Is there any way of using annotations to load all the beans during the bootstrap, and to load lazily for the tests? And is it possible to switch the beans’ connections for the tests?