Spring配置文件中配置property标签的name和ref的区别

原文连接:

https://blog.csdn.net/u010513756/article/details/51597934/

在看李刚的《Java EE企业实战》,里面有一个关于Spring的配置的

<bean id="person" class="service.Person"> <!-- 控制器调用setAxe方法,将容器中的axe bean作为传入的参数 --> <!--此处的name是决定Person类中的那个参数,ref是指bean配置文件中的bean名称--> <property name="axe" ref="axe"></property> </bean>

这里的name和ref虽然是同名的但是name是指Person类中的参数,Person类中有一个Axe类型名叫axe的对象,而ref是当前xml文件中叫做axe的这个bean,把它当作参数传进Person中

猜你喜欢

转载自www.cnblogs.com/lwh-12345/p/13402047.html