File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Spring and the fly likes Is it not a better than Spring IOC to keeping a centralized java class instead of xml Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Is it not a better than Spring IOC to keeping a centralized java class instead of xml " Watch "Is it not a better than Spring IOC to keeping a centralized java class instead of xml " New topic
Author

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

Monica. Shiralkar
Ranch Hand

Joined: Jul 07, 2012
Posts: 639
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
Bartender

Joined: Mar 28, 2008
Posts: 931
    
  44

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.


Tim Driven Development
Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1648
    
    7


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.


[How To Ask Questions][Read before you PM me]
Monica. Shiralkar
Ranch Hand

Joined: Jul 07, 2012
Posts: 639
thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Is it not a better than Spring IOC to keeping a centralized java class instead of xml