File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Is it not a better than Spring IOC to keeping a centralized java class instead of xml

 
Monica Shiralkar
Ranch Hand
Posts: 825
1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Spring IOC removes tight coupling by instantiating objects using xml. I have a doubt.Although this is a good idea but for any developer it is better to set values using a java class instead of an xml. So if we keep a centralized java class and using this class we create objects and reduce tight coupling is it not a better idea than spring IOC. I know there would be 1 disadvantage that it will have to be compiled again but still otherwise is it not a better idea than Spring IOC for java developers?

thanks
 
Tim Cooke
Sheriff
Pie
Posts: 2719
111
Clojure IntelliJ IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are many ways to achieve Dependency Injection and Spring IoC/DI is just one of them. Martin Fowler gives a very good discussion on the different approaches you can take for this in his article Inversion of Control Containers and the Dependency Injection pattern. Specifically what you're talking about with just using Java classes to build your objects is the Service Locator Pattern. Fowler has a section in that article on Using A Service Locator

There's no right answer to which is best to use. I have seen very successful, and definitely not trivial, applications of Spring xml based DI and plain Java only based DI. In some ways I find the plain Java approach more straight forward but the Spring framework is pretty nice too, although I must say that the level of Spring support you get in your IDE makes a huge difference to how easy it is to work with.
 
Bill Gorder
Bartender
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Although this is a good idea but for any developer it is better to set values using a java class instead of an xml.


To the XML comment. Spring has been moving away from XML for a long time now and offers and annotation based Java config (since Spring 3.0). My Spring projects do not have any XML other than for configuring Spring Security and that will go away with the upcoming version (http://spring.io/blog/2013/07/05/spring-security-java-config-preview-oauth). Everything can now be done using Java configuration that means zero XML. Using Java config feels more natural to me and I like the ability to set break points as well.

People need to stop associating Spring with XML, or at least realize its not the only option. You can of course use one or the other or even mix them.

To find out more about Springs java config just Google for 'Spring @Configuration example' or something along those lines. There are tons of examples out there.
 
Monica Shiralkar
Ranch Hand
Posts: 825
1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic