<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: I just do not get it! Why use Spring Beans?</title>
	<atom:link href="http://sadekdrobi.com/2008/12/30/i-just-do-not-get-it-why-use-spring-beans/feed/" rel="self" type="application/rss+xml" />
	<link>http://sadekdrobi.com/2008/12/30/i-just-do-not-get-it-why-use-spring-beans/</link>
	<description>Sadek Drobi</description>
	<lastBuildDate>Mon, 02 Nov 2009 05:56:20 +0100</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: MF2002</title>
		<link>http://sadekdrobi.com/2008/12/30/i-just-do-not-get-it-why-use-spring-beans/comment-page-1/#comment-9533</link>
		<dc:creator>MF2002</dc:creator>
		<pubDate>Wed, 11 Mar 2009 18:08:16 +0000</pubDate>
		<guid isPermaLink="false">http://sadekdrobi.com/2008/12/30/i-just-do-not-get-it-why-use-spring-beans/#comment-9533</guid>
		<description>&quot;Now did it happen to you to forget to declare or mistype your beans in your config? What happens? Runtime exception! What? I thought Java applications are statically typed!&quot;

If you use Spring to manage your beans, and you do not use an init method or implement InitializingBean for its afterPropertiesSet check, and you get a RuntimeException because of that, then you fail.  Period.  The error is on you.  Don&#039;t blame Spring for your failure.  The same would happen if you used &quot;new&quot; and forgot to give an actual reference to your pet constructor.</description>
		<content:encoded><![CDATA[<p>&#8220;Now did it happen to you to forget to declare or mistype your beans in your config? What happens? Runtime exception! What? I thought Java applications are statically typed!&#8221;</p>
<p>If you use Spring to manage your beans, and you do not use an init method or implement InitializingBean for its afterPropertiesSet check, and you get a RuntimeException because of that, then you fail.  Period.  The error is on you.  Don&#8217;t blame Spring for your failure.  The same would happen if you used &#8220;new&#8221; and forgot to give an actual reference to your pet constructor.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Olivier Croisier</title>
		<link>http://sadekdrobi.com/2008/12/30/i-just-do-not-get-it-why-use-spring-beans/comment-page-1/#comment-9404</link>
		<dc:creator>Olivier Croisier</dc:creator>
		<pubDate>Mon, 09 Mar 2009 21:25:18 +0000</pubDate>
		<guid isPermaLink="false">http://sadekdrobi.com/2008/12/30/i-just-do-not-get-it-why-use-spring-beans/#comment-9404</guid>
		<description>Injection is not magic nor a fate.
You can write this :

@Autowired
IFooDao fooDao = DaoFactory.getFooDao(); // or new FooDaoImpl(), or whatever

If the field is injected by Spring, the default value is not set. The opposite is true, too : is Spring doesn&#039; inject the field, guess what, your program will use the standart, manually initialized value.
By doing so, your programm can run whether Spring is available or not. That&#039;s what I call non-invasiveness !</description>
		<content:encoded><![CDATA[<p>Injection is not magic nor a fate.<br />
You can write this :</p>
<p>@Autowired<br />
IFooDao fooDao = DaoFactory.getFooDao(); // or new FooDaoImpl(), or whatever</p>
<p>If the field is injected by Spring, the default value is not set. The opposite is true, too : is Spring doesn&#8217; inject the field, guess what, your program will use the standart, manually initialized value.<br />
By doing so, your programm can run whether Spring is available or not. That&#8217;s what I call non-invasiveness !</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nicolas Martignole</title>
		<link>http://sadekdrobi.com/2008/12/30/i-just-do-not-get-it-why-use-spring-beans/comment-page-1/#comment-7649</link>
		<dc:creator>Nicolas Martignole</dc:creator>
		<pubDate>Tue, 06 Jan 2009 11:18:27 +0000</pubDate>
		<guid isPermaLink="false">http://sadekdrobi.com/2008/12/30/i-just-do-not-get-it-why-use-spring-beans/#comment-7649</guid>
		<description>@Wolter comment #19
I&#039;ve seen Spring usage for integration issue within application, whereas this problem should be solve by lightweight integration framework such as Mule, Apache ServiceMix or Apache Camel. I do work also in a bank, we have some Spring usage in our application, but not for integration issue such as Cobol communication as you mentioned.
Have a look at Spring Integration, another interesting framework that&#039;s worth to try and avoid too many technical glue code.

@Sadache : nice post, I think you underestimate the amount of &quot;I love/I hate Spring&quot;. I really appreciate the comments, still interesting. 
There&#039;s also another subject that you should have a look : &quot;Do I still need Spring IoC when I write EJB3.1 apps only?&quot; There was a nice presentation at Devoxx 2008, I&#039;ll send you the link by mail.</description>
		<content:encoded><![CDATA[<p>@Wolter comment #19<br />
I&#8217;ve seen Spring usage for integration issue within application, whereas this problem should be solve by lightweight integration framework such as Mule, Apache ServiceMix or Apache Camel. I do work also in a bank, we have some Spring usage in our application, but not for integration issue such as Cobol communication as you mentioned.<br />
Have a look at Spring Integration, another interesting framework that&#8217;s worth to try and avoid too many technical glue code.</p>
<p>@Sadache : nice post, I think you underestimate the amount of &#8220;I love/I hate Spring&#8221;. I really appreciate the comments, still interesting.<br />
There&#8217;s also another subject that you should have a look : &#8220;Do I still need Spring IoC when I write EJB3.1 apps only?&#8221; There was a nice presentation at Devoxx 2008, I&#8217;ll send you the link by mail.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Wolter</title>
		<link>http://sadekdrobi.com/2008/12/30/i-just-do-not-get-it-why-use-spring-beans/comment-page-1/#comment-7575</link>
		<dc:creator>Wolter</dc:creator>
		<pubDate>Sun, 04 Jan 2009 16:17:07 +0000</pubDate>
		<guid isPermaLink="false">http://sadekdrobi.com/2008/12/30/i-just-do-not-get-it-why-use-spring-beans/#comment-7575</guid>
		<description>@John

I just read the entire article, and I fail to see how I am not correct, unless it is simply a misunderstanding due to the medium being used for idea exchange (As Sadache so astutely pointed out, I have not posted any interaction diagrams in this text-only forum).

What I have found is that in general, using interfaces just to be flexible is a waste of resources and unnecessarily bloats the code.  The majority of the code you write for most projects is domain specific, task specific, and is highly unlikely to be reused.
In the event that code IS targeted for reuse, it&#039;s not very hard to abstract an interface (hell, most IDEs can do it with a single click of the mouse!).
What&#039;s more, larger code reuse efforts in the business world involve taking business or data logic and centralizing it via distributed interfaces.  This happens after it&#039;s discovered that multiple projects by different teams are doing essentially the same thing, and it&#039;s ALWAYS implemented differently in different projects.  You&#039;d be hard pressed to have such intricate control over the designs in your software house that you&#039;d catch these things, unless you became such a micro-manager that all of your developers quit in disgust.

Sticking to concrete classes but using DI for wiring gets you halfway to full code portability while at the same time reducing boilerplate and ugly service finders that shouldn&#039;t be in your unrelated code.  Making it fully portable is a simple matter of making an abstraction that matches the common behavior between the existing implementation and the new extra implementation, making a few changes using the many refactoring tools of your IDE, and recompiling.  Usually this takes me no more than half an hour.

The article&#039;s complaints about having to at least recompile the Button module don&#039;t apply to dynamically linked languages like Java and C#, so you&#039;re only left with having to change Button if the PUBLIC INTERFACE of Lamp changes, an unlikely scenario indeed, and once again mitigated by refactoring tools.

Use sound design principles that match the circumstances.  Only add indirection if you have compelling evidence that you&#039;ll need it in the future and the cost of doing it now will be considerably less.  100% flexible code results in a programming language.</description>
		<content:encoded><![CDATA[<p>@John</p>
<p>I just read the entire article, and I fail to see how I am not correct, unless it is simply a misunderstanding due to the medium being used for idea exchange (As Sadache so astutely pointed out, I have not posted any interaction diagrams in this text-only forum).</p>
<p>What I have found is that in general, using interfaces just to be flexible is a waste of resources and unnecessarily bloats the code.  The majority of the code you write for most projects is domain specific, task specific, and is highly unlikely to be reused.<br />
In the event that code IS targeted for reuse, it&#8217;s not very hard to abstract an interface (hell, most IDEs can do it with a single click of the mouse!).<br />
What&#8217;s more, larger code reuse efforts in the business world involve taking business or data logic and centralizing it via distributed interfaces.  This happens after it&#8217;s discovered that multiple projects by different teams are doing essentially the same thing, and it&#8217;s ALWAYS implemented differently in different projects.  You&#8217;d be hard pressed to have such intricate control over the designs in your software house that you&#8217;d catch these things, unless you became such a micro-manager that all of your developers quit in disgust.</p>
<p>Sticking to concrete classes but using DI for wiring gets you halfway to full code portability while at the same time reducing boilerplate and ugly service finders that shouldn&#8217;t be in your unrelated code.  Making it fully portable is a simple matter of making an abstraction that matches the common behavior between the existing implementation and the new extra implementation, making a few changes using the many refactoring tools of your IDE, and recompiling.  Usually this takes me no more than half an hour.</p>
<p>The article&#8217;s complaints about having to at least recompile the Button module don&#8217;t apply to dynamically linked languages like Java and C#, so you&#8217;re only left with having to change Button if the PUBLIC INTERFACE of Lamp changes, an unlikely scenario indeed, and once again mitigated by refactoring tools.</p>
<p>Use sound design principles that match the circumstances.  Only add indirection if you have compelling evidence that you&#8217;ll need it in the future and the cost of doing it now will be considerably less.  100% flexible code results in a programming language.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: johnofanger</title>
		<link>http://sadekdrobi.com/2008/12/30/i-just-do-not-get-it-why-use-spring-beans/comment-page-1/#comment-7554</link>
		<dc:creator>johnofanger</dc:creator>
		<pubDate>Sat, 03 Jan 2009 20:41:31 +0000</pubDate>
		<guid isPermaLink="false">http://sadekdrobi.com/2008/12/30/i-just-do-not-get-it-why-use-spring-beans/#comment-7554</guid>
		<description>Thanks for the wonderful post. 

I get pimples when exposed to 25klos xml configuration. You love it? Well, you may, but you loose lots of stuff the javacc makes you bleed for. 
In my eyes it is a silly idea to use the &quot;simple&quot; frameworks. 
Even the sort of - well let me call it interesting - EJB spec seems light weight compared to the weight Spring imposes on me (okay, EJB is for RPC only, however ...).

@cyrill: To say it in a nice manner: If your shop has no discipline, it has no discipline. Full Stop. And good luck when checking discipline in 25klos xml configuration!
@cyrill: IOC was discussed long time BEFORE spring, though it was named another way - If I&#039;m right it started out with DIP (http://www.objectmentor.com/resources/articles/dip.pdf). Thanks to Fowler every name changes :-(. You can do IOC with and without containers. Actually try to rewrite your code WITHOUT Spring and you will be surprised, how much easier it is to comperehend, and most probably even shorter in length.

@sadache: It&#039;s the Java &quot;Architects&quot; that love stuff like Spring. Did you know, you do not have to know Java programming to become a &quot;Architect&quot;. Try to talk to them about nice stuff, like constructing your main application by healthy sized apps, ACID and CAP. Nogo. Or try to make them apply (in contrast to only naming) simple design, architecture or documentation rules and they will fail.

@wolter: You are , well, I&#039;d say, not fully correct. Please check the link above (DIP).

@evan: You can do this all with good plain old Java and core Java APIs. Just give it a try. And please compare the 25 klos xml with the size of the additional glue code. The glue code will be shorter.

@dizzy: Well, sort of funny. That sort of answer the same way, whenever I am asked about a weakness: &quot;Well, it isn&#039;t that bad if only ...&quot;. Your answer states that it is bad.

@Sakuraba: No, spring was not the first Java IoC framework. I was once forced to use Avalon(http://avalon.apache.org/closed.html) ...


####################
THAT SAID: Just give good plain old Java a try. You&#039;ll be surprised, how good it fits.
####################

Thank you for this post.

Regards

  John</description>
		<content:encoded><![CDATA[<p>Thanks for the wonderful post. </p>
<p>I get pimples when exposed to 25klos xml configuration. You love it? Well, you may, but you loose lots of stuff the javacc makes you bleed for.<br />
In my eyes it is a silly idea to use the &#8220;simple&#8221; frameworks.<br />
Even the sort of &#8211; well let me call it interesting &#8211; EJB spec seems light weight compared to the weight Spring imposes on me (okay, EJB is for RPC only, however &#8230;).</p>
<p>@cyrill: To say it in a nice manner: If your shop has no discipline, it has no discipline. Full Stop. And good luck when checking discipline in 25klos xml configuration!<br />
@cyrill: IOC was discussed long time BEFORE spring, though it was named another way &#8211; If I&#8217;m right it started out with DIP (<a href="http://www.objectmentor.com/resources/articles/dip.pdf)" rel="nofollow">http://www.objectmentor.com/resources/articles/dip.pdf)</a>. Thanks to Fowler every name changes :-(. You can do IOC with and without containers. Actually try to rewrite your code WITHOUT Spring and you will be surprised, how much easier it is to comperehend, and most probably even shorter in length.</p>
<p>@sadache: It&#8217;s the Java &#8220;Architects&#8221; that love stuff like Spring. Did you know, you do not have to know Java programming to become a &#8220;Architect&#8221;. Try to talk to them about nice stuff, like constructing your main application by healthy sized apps, ACID and CAP. Nogo. Or try to make them apply (in contrast to only naming) simple design, architecture or documentation rules and they will fail.</p>
<p>@wolter: You are , well, I&#8217;d say, not fully correct. Please check the link above (DIP).</p>
<p>@evan: You can do this all with good plain old Java and core Java APIs. Just give it a try. And please compare the 25 klos xml with the size of the additional glue code. The glue code will be shorter.</p>
<p>@dizzy: Well, sort of funny. That sort of answer the same way, whenever I am asked about a weakness: &#8220;Well, it isn&#8217;t that bad if only &#8230;&#8221;. Your answer states that it is bad.</p>
<p>@Sakuraba: No, spring was not the first Java IoC framework. I was once forced to use Avalon(http://avalon.apache.org/closed.html) &#8230;</p>
<p>####################<br />
THAT SAID: Just give good plain old Java a try. You&#8217;ll be surprised, how good it fits.<br />
####################</p>
<p>Thank you for this post.</p>
<p>Regards</p>
<p>  John</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sadache</title>
		<link>http://sadekdrobi.com/2008/12/30/i-just-do-not-get-it-why-use-spring-beans/comment-page-1/#comment-7525</link>
		<dc:creator>Sadache</dc:creator>
		<pubDate>Fri, 02 Jan 2009 19:24:20 +0000</pubDate>
		<guid isPermaLink="false">http://sadekdrobi.com/2008/12/30/i-just-do-not-get-it-why-use-spring-beans/#comment-7525</guid>
		<description>@Wolter

Unfortunately I will be mistaken whatever I comment on your example. I know nothing about your business context which I consider essential for any design or architecture.
Again, what you gave as information is about the static structure and not runtime behavior. You know class diagram vs object diagram and sequence diagram.</description>
		<content:encoded><![CDATA[<p>@Wolter</p>
<p>Unfortunately I will be mistaken whatever I comment on your example. I know nothing about your business context which I consider essential for any design or architecture.<br />
Again, what you gave as information is about the static structure and not runtime behavior. You know class diagram vs object diagram and sequence diagram.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sadache</title>
		<link>http://sadekdrobi.com/2008/12/30/i-just-do-not-get-it-why-use-spring-beans/comment-page-1/#comment-7524</link>
		<dc:creator>Sadache</dc:creator>
		<pubDate>Fri, 02 Jan 2009 18:49:20 +0000</pubDate>
		<guid isPermaLink="false">http://sadekdrobi.com/2008/12/30/i-just-do-not-get-it-why-use-spring-beans/#comment-7524</guid>
		<description>@gl

&lt;blockquote&gt;
No, it is not a lot of work, for one class. Dozens, hundreds, or thousands of classes, yes, that is too much work and a far worse smell than (constructor-injected) DI. Other users of your library either have to have access to your source (or you have to write very explicit javadocs) to know in what contexts to use what constructors. Plus, whereas Spring â€œmagicâ€ might lead to runtime NPE (again, 100% avoidable with constructor injection), in your example you can also create situations where the use of the wrong constructor might actually succeed, altering production context or data, when it is not intended. That is far worse, and far more likely to happen unless you have extremely tight control over every coder in your team.
&lt;/blockquote&gt;
You do not need to make the unit tests targeted constructors public, just keep them package private. 
Inside the package itself, well that is a less important concern, and indeed you can either add JavaDoc (which is a good practice) or use annotations to generate warnings.
Constructors allow you to use final fields which guaranteed no mutation to your objects&#039; state when necessary (IMO always).
&lt;blockquote&gt;
Yes, because multiple situational constructors is mandatory and explicitly type checked, and does not require any extra conceptual or cultural baggage on the part of users or developers.   In addition to the above, there is also no way for a new developer on your team to know which (and how) properties are set other than to walk the constructor chain of each dependency. That sounds like a recipe for failure for any but the smallest, most tightly controlled culture teams. 
&lt;/blockquote&gt; 
You do not need to follow constructors chain. At each level of composition a parameterless constructor sets its dependencies for production. So for instance if you want to know what is your EmployerSalleryCalculator depending on, well you see the parameterless constructor. Of course now you can ask yourself further questions about the composition of its components, but you know again where to find it. Each concrete class is responsible for specifying its dependencies. Isn&#039;t that the single responsibility and separation of concerns principle? I am afraid Spring does not follow the principle...
And by the way, you have never had to walk dependencies chains in different Spring configurations files? I am sure constructors are more navigable. Everyone got ctrl+click!

&lt;blockquote&gt;
 versus your magic constructors that can succeed long enough to cause damage
&lt;/blockquote&gt;
I am afraid I didn&#039;t get your argument. You mean you can not change at runtime what is @AutoWrapp ed? When as I told you can control the visibility of your constructors and expose only parameterless ones.
&lt;blockquote&gt;
It takes about 30 seconds to find the Guice project site, which contains numerous references. 
&lt;/blockquote&gt;
I am not doubting the success of projects based on Guice or DI in general. I am just sure there are a lot a lot of projects that succeed with no DI.

From your argument I could understand that you are for Constructor Injection which is good. But then you try to show that constructors are bad (where as I described above, I disagree with you). So what are you for?

BTW: I like what Guice states 
Wherever possible, use constructor injection to create immutable objects. Immutable objects are simple, shareable, and can be composed
</description>
		<content:encoded><![CDATA[<p>@gl</p>
<blockquote><p>
No, it is not a lot of work, for one class. Dozens, hundreds, or thousands of classes, yes, that is too much work and a far worse smell than (constructor-injected) DI. Other users of your library either have to have access to your source (or you have to write very explicit javadocs) to know in what contexts to use what constructors. Plus, whereas Spring â€œmagicâ€ might lead to runtime NPE (again, 100% avoidable with constructor injection), in your example you can also create situations where the use of the wrong constructor might actually succeed, altering production context or data, when it is not intended. That is far worse, and far more likely to happen unless you have extremely tight control over every coder in your team.
</p></blockquote>
<p>You do not need to make the unit tests targeted constructors public, just keep them package private.<br />
Inside the package itself, well that is a less important concern, and indeed you can either add JavaDoc (which is a good practice) or use annotations to generate warnings.<br />
Constructors allow you to use final fields which guaranteed no mutation to your objects&#8217; state when necessary (IMO always).</p>
<blockquote><p>
Yes, because multiple situational constructors is mandatory and explicitly type checked, and does not require any extra conceptual or cultural baggage on the part of users or developers.   In addition to the above, there is also no way for a new developer on your team to know which (and how) properties are set other than to walk the constructor chain of each dependency. That sounds like a recipe for failure for any but the smallest, most tightly controlled culture teams.
</p></blockquote>
<p>You do not need to follow constructors chain. At each level of composition a parameterless constructor sets its dependencies for production. So for instance if you want to know what is your EmployerSalleryCalculator depending on, well you see the parameterless constructor. Of course now you can ask yourself further questions about the composition of its components, but you know again where to find it. Each concrete class is responsible for specifying its dependencies. Isn&#8217;t that the single responsibility and separation of concerns principle? I am afraid Spring does not follow the principle&#8230;<br />
And by the way, you have never had to walk dependencies chains in different Spring configurations files? I am sure constructors are more navigable. Everyone got ctrl+click!</p>
<blockquote><p>
 versus your magic constructors that can succeed long enough to cause damage
</p></blockquote>
<p>I am afraid I didn&#8217;t get your argument. You mean you can not change at runtime what is @AutoWrapp ed? When as I told you can control the visibility of your constructors and expose only parameterless ones.</p>
<blockquote><p>
It takes about 30 seconds to find the Guice project site, which contains numerous references.
</p></blockquote>
<p>I am not doubting the success of projects based on Guice or DI in general. I am just sure there are a lot a lot of projects that succeed with no DI.</p>
<p>From your argument I could understand that you are for Constructor Injection which is good. But then you try to show that constructors are bad (where as I described above, I disagree with you). So what are you for?</p>
<p>BTW: I like what Guice states<br />
Wherever possible, use constructor injection to create immutable objects. Immutable objects are simple, shareable, and can be composed</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: gl</title>
		<link>http://sadekdrobi.com/2008/12/30/i-just-do-not-get-it-why-use-spring-beans/comment-page-1/#comment-7516</link>
		<dc:creator>gl</dc:creator>
		<pubDate>Fri, 02 Jan 2009 05:30:03 +0000</pubDate>
		<guid isPermaLink="false">http://sadekdrobi.com/2008/12/30/i-just-do-not-get-it-why-use-spring-beans/#comment-7516</guid>
		<description>Quoting out of order---
&gt;First of all, if you want to use Spring Beans you need to believe in magic. Donâ€™t agree?

1) 100% avoidable with constructor injection.  

&gt;Now did it happen to you to forget to declare or mistype your beans in your config? What happens? Runtime exception! What? I thought Java applications are statically typed!

2) A huge problem with Spring XML, but not with DI in general.  Guice, as others have pointed out, has no such problem, nor does Spring JavaConfig. 

&gt;Loose coupling is a fruit of good design and architecture, and Spring, DI or IoC have nothing to do with that. For testability and loose coupling I can have two constructors, one parameterless that specifies â€œDAOâ€ dependencies for production code, and another with parameters to be used when testing. Did that look like a lot of work?

No, it is not a lot of work, for one class.  Dozens, hundreds, or thousands of classes, yes, that is too much work and a far worse smell than (constructor-injected) DI.  Other users of your library either have to have access to your source (or you have to write very explicit javadocs) to know in what contexts to use what constructors.  Plus, whereas Spring &quot;magic&quot; might lead to runtime NPE (again, 100% avoidable with constructor injection), in your example you can also create situations where the use of the wrong constructor might actually succeed, altering production context or data, when it is not intended.  That is far worse, and far more likely to happen unless you have extremely tight control over every coder in your team.  Externalizing these things in properties files?  Congratulations, you may not want to call it that, but properties files are conceptually similar to DI.  (As you say, DI is not rocket science -- it is just handing an object its dependencies.)  And back to testing, this way also presents you much more work to perform integration testing of several classes in concert, since you have to construct the proper constructor chain for every object in the test, every time, for every such test.  If DI is a smell, this is a fetid stench.

&gt;Now I can hear you, use annotations! Annotations solves your problem! Well I am afraid not. Annotations like @Required or @AutoWired is just like begging the user not delete the field or property, and it is not mandatory and not forced by any checker. Remember, I am talking culture hereâ€¦
Yes, because multiple situational constructors is mandatory and explicitly type checked, and does not require any extra conceptual or cultural baggage on the part of users or developers.  :) In addition to the above, there is also no way for a new developer on your team to know which (and how) properties are set other than to walk the constructor chain of each dependency.  That sounds like a recipe for failure for any but the smallest, most tightly controlled culture teams.  I will not take Spring XML given the choice, but if I had to choose between ugly XML and classes with @Required that fail only at runtime at startup, versus your magic constructors that can succeed long enough to cause damage, I will take the ugly XML every time.  Sorry, but your solution solves one problem by creating a far worse one.

&gt;I guess this is an over exaggerated argument, can you explain more or point me to links?

It takes about 30 seconds to find the Guice project site, which contains numerous references.  Most of the Bob Lee&#039;s explanation about Guice&#039;s role in AdWords and at Google are in the linked videos, so it is hard to quote here.  Here is a summary quote, from the Spring comparison page:
http://code.google.com/p/google-guice/wiki/SpringComparison

&quot;Guice is anything but a rehash of Spring. Guice was born purely out of use cases from one of Google&#039;s biggest (in every way) applications: AdWords. We sat down and asked ourselves, how do we really want to build this application going forward? Guice enables our answer. &quot;

&gt;OOP is about relationships between instances not between classes. Spring emphasizes classes and ignores so much instances. I know you can use â€œprototypeâ€ but you do it in a much of a static way (because Spring configuration files are static).

Spring manages relationships between instances, and, while you are correct that the most common Spring case is managing single instances of service classes (effectively, though not literally, singletons), Spring has had more options than &quot;singleton&quot;/prototype for a couple of years now.  It ships with support for request, session, and global session, and provides you the ability to define your own custom scopes as required.
http://static.springframework.org/spring/docs/2.0.x/reference/beans.html#beans-factory-scopes

Don&#039;t get me wrong -- Spring is heavy, and not appropriate for many places where people blindly plug it in.  I agree that despite claims of it being &quot;non-intrusive,&quot; it does encourage a certain style in your code, which is intrusion, in a way.  There are oodles of projects where I would not use Spring, and some where I would not use DI.  But this blog entry sets up strawmen arguments using outdated information and presents even worse solutions.</description>
		<content:encoded><![CDATA[<p>Quoting out of order&#8212;<br />
&gt;First of all, if you want to use Spring Beans you need to believe in magic. Donâ€™t agree?</p>
<p>1) 100% avoidable with constructor injection.  </p>
<p>&gt;Now did it happen to you to forget to declare or mistype your beans in your config? What happens? Runtime exception! What? I thought Java applications are statically typed!</p>
<p>2) A huge problem with Spring XML, but not with DI in general.  Guice, as others have pointed out, has no such problem, nor does Spring JavaConfig. </p>
<p>&gt;Loose coupling is a fruit of good design and architecture, and Spring, DI or IoC have nothing to do with that. For testability and loose coupling I can have two constructors, one parameterless that specifies â€œDAOâ€ dependencies for production code, and another with parameters to be used when testing. Did that look like a lot of work?</p>
<p>No, it is not a lot of work, for one class.  Dozens, hundreds, or thousands of classes, yes, that is too much work and a far worse smell than (constructor-injected) DI.  Other users of your library either have to have access to your source (or you have to write very explicit javadocs) to know in what contexts to use what constructors.  Plus, whereas Spring &#8220;magic&#8221; might lead to runtime NPE (again, 100% avoidable with constructor injection), in your example you can also create situations where the use of the wrong constructor might actually succeed, altering production context or data, when it is not intended.  That is far worse, and far more likely to happen unless you have extremely tight control over every coder in your team.  Externalizing these things in properties files?  Congratulations, you may not want to call it that, but properties files are conceptually similar to DI.  (As you say, DI is not rocket science &#8212; it is just handing an object its dependencies.)  And back to testing, this way also presents you much more work to perform integration testing of several classes in concert, since you have to construct the proper constructor chain for every object in the test, every time, for every such test.  If DI is a smell, this is a fetid stench.</p>
<p>&gt;Now I can hear you, use annotations! Annotations solves your problem! Well I am afraid not. Annotations like @Required or @AutoWired is just like begging the user not delete the field or property, and it is not mandatory and not forced by any checker. Remember, I am talking culture hereâ€¦<br />
Yes, because multiple situational constructors is mandatory and explicitly type checked, and does not require any extra conceptual or cultural baggage on the part of users or developers.  :) In addition to the above, there is also no way for a new developer on your team to know which (and how) properties are set other than to walk the constructor chain of each dependency.  That sounds like a recipe for failure for any but the smallest, most tightly controlled culture teams.  I will not take Spring XML given the choice, but if I had to choose between ugly XML and classes with @Required that fail only at runtime at startup, versus your magic constructors that can succeed long enough to cause damage, I will take the ugly XML every time.  Sorry, but your solution solves one problem by creating a far worse one.</p>
<p>&gt;I guess this is an over exaggerated argument, can you explain more or point me to links?</p>
<p>It takes about 30 seconds to find the Guice project site, which contains numerous references.  Most of the Bob Lee&#8217;s explanation about Guice&#8217;s role in AdWords and at Google are in the linked videos, so it is hard to quote here.  Here is a summary quote, from the Spring comparison page:<br />
<a href="http://code.google.com/p/google-guice/wiki/SpringComparison" rel="nofollow">http://code.google.com/p/google-guice/wiki/SpringComparison</a></p>
<p>&#8220;Guice is anything but a rehash of Spring. Guice was born purely out of use cases from one of Google&#8217;s biggest (in every way) applications: AdWords. We sat down and asked ourselves, how do we really want to build this application going forward? Guice enables our answer. &#8221;</p>
<p>&gt;OOP is about relationships between instances not between classes. Spring emphasizes classes and ignores so much instances. I know you can use â€œprototypeâ€ but you do it in a much of a static way (because Spring configuration files are static).</p>
<p>Spring manages relationships between instances, and, while you are correct that the most common Spring case is managing single instances of service classes (effectively, though not literally, singletons), Spring has had more options than &#8220;singleton&#8221;/prototype for a couple of years now.  It ships with support for request, session, and global session, and provides you the ability to define your own custom scopes as required.<br />
<a href="http://static.springframework.org/spring/docs/2.0.x/reference/beans.html#beans-factory-scopes" rel="nofollow">http://static.springframework.org/spring/docs/2.0.x/reference/beans.html#beans-factory-scopes</a></p>
<p>Don&#8217;t get me wrong &#8212; Spring is heavy, and not appropriate for many places where people blindly plug it in.  I agree that despite claims of it being &#8220;non-intrusive,&#8221; it does encourage a certain style in your code, which is intrusion, in a way.  There are oodles of projects where I would not use Spring, and some where I would not use DI.  But this blog entry sets up strawmen arguments using outdated information and presents even worse solutions.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Thomas J Clancy</title>
		<link>http://sadekdrobi.com/2008/12/30/i-just-do-not-get-it-why-use-spring-beans/comment-page-1/#comment-7503</link>
		<dc:creator>Thomas J Clancy</dc:creator>
		<pubDate>Thu, 01 Jan 2009 20:12:14 +0000</pubDate>
		<guid isPermaLink="false">http://sadekdrobi.com/2008/12/30/i-just-do-not-get-it-why-use-spring-beans/#comment-7503</guid>
		<description>Spring, despite its claim that it is a lightweight container, is too big, too cumbersome and overly complex.  In short, it sucks.  Probably as much as Hibernate does.  And why is this the case?  The Java language (and I am a long-time Java programmer), by its very nature, ultimately leads to this kind of complexity, which is almost as bad as the obscurity that comes with template programming in C++.  Yuck.</description>
		<content:encoded><![CDATA[<p>Spring, despite its claim that it is a lightweight container, is too big, too cumbersome and overly complex.  In short, it sucks.  Probably as much as Hibernate does.  And why is this the case?  The Java language (and I am a long-time Java programmer), by its very nature, ultimately leads to this kind of complexity, which is almost as bad as the obscurity that comes with template programming in C++.  Yuck.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Wolter</title>
		<link>http://sadekdrobi.com/2008/12/30/i-just-do-not-get-it-why-use-spring-beans/comment-page-1/#comment-7497</link>
		<dc:creator>Wolter</dc:creator>
		<pubDate>Thu, 01 Jan 2009 17:00:47 +0000</pubDate>
		<guid isPermaLink="false">http://sadekdrobi.com/2008/12/30/i-just-do-not-get-it-why-use-spring-beans/#comment-7497</guid>
		<description>&gt; OOP is about relationships between instances not between classes. Spring emphasizes classes and ignores so much instances. I know you can use â€œprototypeâ€ but you do it in a much of a static way (because Spring configuration files are static).

I&#039;m not quite sure I follow here...  Some things simply are class relationships. For example:

bean logger:
- property logDao, ref logDao
- property currentUser, ref currentUserProxy
- property userDao, ref userDao
- property properties, ref primaryProperties

bean logPurger:
- property logDao, ref logDao
- property properties, ref primaryProperties

In this case, it makes sense to have one logger and one log purger.  So many of these objects have an instantiation lifetime AND relationship lifetime that is equivalent to the running time of the program, so singleton makes sense.

The current user IS dynamic, but since the user data could reside in different dynamic data pools depending on how you access the system (via web, command line, TCP/IP link with some custom credentials and session mechanism and such, I ended up making this a proxy class that seeks out where the true data is stored.
In this case, I&#039;m not sure how it could have been done differently.  The current user has a MUCH shorter lifespan than the business objects + a few services that need to know about it, so it would make sense to have a long-lived proxy service that does the legwork of finding the information about the shorter-lived data.

On the web interface side, you have a LOT of short lived objects that present the view to the user.  These objects make use of business and services, but are short-lived themselves:

operations job editor (not singleton):
- property localization, ref masterLocalization (references a singleton)
- property operationsJobBusiness, ref operationsJobBusiness (references a singleton)
- property log, ref logger (references a singleton)
- property table, ref operationsJobTable (not singleton)
- property editRequestor, ref operationsJobEditRequestor (not singleton)

Any time the UI requests the job editor screen, it gets a new instance.  It makes use of some complex UI components which are built on-the-fly and added via spring.  When the user leaves the screen, the editor and any non-singletons it uses are dereferenced.

I chose not to autowire in this project for fear that it would make for some very difficult-to-find null references, but I&#039;m starting to think that perhaps a hybrid approach would work well: autowiring for long-lived singleton references, specific wiring for short-lived stuff.

Now, doing all this in an xml file is definitely not the nicest way to do things, which is why I point to the deficiencies in the Java language, rather than the concept itself.  Direct language support for managing dynamic relationships and configuration without loads of boilerplate would be very nice, indeed.</description>
		<content:encoded><![CDATA[<p>&gt; OOP is about relationships between instances not between classes. Spring emphasizes classes and ignores so much instances. I know you can use â€œprototypeâ€ but you do it in a much of a static way (because Spring configuration files are static).</p>
<p>I&#8217;m not quite sure I follow here&#8230;  Some things simply are class relationships. For example:</p>
<p>bean logger:<br />
- property logDao, ref logDao<br />
- property currentUser, ref currentUserProxy<br />
- property userDao, ref userDao<br />
- property properties, ref primaryProperties</p>
<p>bean logPurger:<br />
- property logDao, ref logDao<br />
- property properties, ref primaryProperties</p>
<p>In this case, it makes sense to have one logger and one log purger.  So many of these objects have an instantiation lifetime AND relationship lifetime that is equivalent to the running time of the program, so singleton makes sense.</p>
<p>The current user IS dynamic, but since the user data could reside in different dynamic data pools depending on how you access the system (via web, command line, TCP/IP link with some custom credentials and session mechanism and such, I ended up making this a proxy class that seeks out where the true data is stored.<br />
In this case, I&#8217;m not sure how it could have been done differently.  The current user has a MUCH shorter lifespan than the business objects + a few services that need to know about it, so it would make sense to have a long-lived proxy service that does the legwork of finding the information about the shorter-lived data.</p>
<p>On the web interface side, you have a LOT of short lived objects that present the view to the user.  These objects make use of business and services, but are short-lived themselves:</p>
<p>operations job editor (not singleton):<br />
- property localization, ref masterLocalization (references a singleton)<br />
- property operationsJobBusiness, ref operationsJobBusiness (references a singleton)<br />
- property log, ref logger (references a singleton)<br />
- property table, ref operationsJobTable (not singleton)<br />
- property editRequestor, ref operationsJobEditRequestor (not singleton)</p>
<p>Any time the UI requests the job editor screen, it gets a new instance.  It makes use of some complex UI components which are built on-the-fly and added via spring.  When the user leaves the screen, the editor and any non-singletons it uses are dereferenced.</p>
<p>I chose not to autowire in this project for fear that it would make for some very difficult-to-find null references, but I&#8217;m starting to think that perhaps a hybrid approach would work well: autowiring for long-lived singleton references, specific wiring for short-lived stuff.</p>
<p>Now, doing all this in an xml file is definitely not the nicest way to do things, which is why I point to the deficiencies in the Java language, rather than the concept itself.  Direct language support for managing dynamic relationships and configuration without loads of boilerplate would be very nice, indeed.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

