Announcement Announcement Module
Collapse
No announcement yet.
Bean declaration in context files vs autowire annotations Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Bean declaration in context files vs autowire annotations

    Hi,

    Im going to upgrade my web application from Spring 2.5.4 to Spring 3.0.5.

    Also, were going to start a new application in Spring 3.0.5.

    Were used to the traditional xml application context declaration.

    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, Ill 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?

    Thanks in advance.
Working...
X