Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Design query

 
pawan chopra
Ranch Hand
Posts: 417
jQuery Mac Objective C
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I have a question related to frameworks like Spring. We can create factory patterns and service locators in java and can achieve what spring is providing through defining beans in the xml file then why do we prefer XML config files over java?
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We don't, necessarily--it depends on your needs. One advantage of Spring is that the hard work has already been done, whether or not you use XML for configuration.

I still use XML configuration a lot, though, particularly when I have to target multiple environments (which I frequently do) or if there's a lot of setup for deep, but still partial, integration tests.
 
Mark Secrist
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Pawan,
Spring provides A way to compose application components but isn't necessarily THE way to do it. A lot depends on how dynamic your composition needs to be. Spring allows for XML based composition, which means changes can be made simply by restarting the application (and re-reading the XML file). Alternatively, configuration can be done in the Java code with annotations, but the changes don't take effect until re-compile. If you need changes in mid-run, then another approach will be required.

Also, the Spring framework offers much more than just DI. DI just happens to be one of the patterns for composing applications and isn't necessarily required in many cases.

Mark
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mark Secrist wrote:If you need changes in mid-run, then another approach will be required.

Not necessarily a *completely* different approach; at the very least JRebel supports hot-loading of Spring config files.
 
Mark Secrist
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Interesting... I didn't know that. Thanks for the tip.
 
pawan chopra
Ranch Hand
Posts: 417
jQuery Mac Objective C
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks alot for the information.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic