在Spring中,有三种方式注入值到 bean 属性。
正常的方式
快捷方式
“p” 模式
新建一个User类,它包含username和password两个属性,现在使用spring的IOC注入值到该bean。
1.正常方式
在一个“value”标签注入值,并附有“property”标签结束。
<beans xmlns="http://.example.User" p:username="scott" p:password="tiger" /> </beans>记住声明xmlns:p=”http://www.springframework.org/schema/p" 在Spring XML bean配置文件。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。