what is the use of the setter dependency injection in Spring?

What is the use of the dependency setter injection ?

In a database driven app, I retrieve results, use the javabeans set methods to save stuff in javabeans and then call get on it.

What is the use of having something set externally from a xml already ?

Can someone provide an example when the setter injection can be used?

I wouldnt imaginge using it to get usernames, passwords, databaseurl because we use JNDI for that...

Is the dependency setter meant as something additional to web.xml so you dont have to get params from web.xml?

[571 byte] By [keepswimminga] at [2007-10-2 13:42:47]
# 1
Mainly if you use Spring's 'auto-wiring' feature to chain dependent objects together. An example is a Hibernate object that exposes a setter to recieve a transaction or data source (though you could more easily use Spring's own Hibernate classes for this as well).- Saish
Saisha at 2007-7-13 11:37:38 > top of Java-index,Other Topics,Patterns & OO Design...
# 2
So a simple bean can for example: datasource or jndi name is looked up from the xml file instead of writing it in the code. And you call that bean's getters to get the datasource values.. ?
keepswimminga at 2007-7-13 11:37:38 > top of Java-index,Other Topics,Patterns & OO Design...
# 3

No, you would indicate in the XML that the Hibernate object and the TransactionFactory (I am being vague here) have a dependency. You then specify whether you want setter or constructor injection. When Spring creates the Hibernate Object, it will attempt to also create a TransactionFactory and pass that to the Hibernate Object's setter. "Auto-wiring" them together for you.

- Saish

Saisha at 2007-7-13 11:37:38 > top of Java-index,Other Topics,Patterns & OO Design...