Java framework learning (2)-Spring dependency injection

Posted May 25, 20201 min read

Spring dependency injection

Assigning values to properties by set-get/set method is required

<bean name = "user" class = "com.Bean.User">
    <property name = "name" value = "wwy"> </property>
    <property name = "age" value = "18"> </property>
</bean>

Inject through the constructor-a constructor with corresponding parameters

<bean name = "user" class = "com.Bean.User">
    <constructor-arg name = "name" value = "wwy" />
    <constructor-arg name = "age" value = "18" />
</bean>