XML
<bean name="helloWorld" class="com.company.HelloWorld">
<property name="msg" value="messaging"/>
</bean>
JAVA
package com.company;
// ...
public class HelloWorld {
private String msg;
public void setMsg(String msg) { this.msg = msg; }
}
As shown above, property "msg" is injected into "this.msg" by "setMsg" method, which I understand as "Property Injection". As far as I'm concerned, Spring's DI was promoted to decouple classes, but the above codes just inject properties. And I wonder whether property injection is based on DI in Spring. Hope someone could help me.
Injection means that the required dependencies (in your case: a simple String) are set from outside (this could be done manually or as in your case by a DI container - spring). So your class does not have to know where the value of "msg" is configured / retrieved, but it knows that (upon creation) it receives the correct value.
To answer your question: yes, property injection is a kind of dependency injection. The other possibility (that is usually preferred) is the constructor-injection, where your class has to declare all it's dependencies within the constructor. The DI framework (spring) then injects the dependencies during object construction...