通过ref来配置bean1
2025-4-20
| 2025-4-20
Words 265Read Time 1 min
type
status
date
slug
summary
tags
category
icon
password

对象依赖

对象之间的依赖,一个类里面引用另一个对象在编程中很常见,可以使用new对象的方式,在一个类里面,用new出来的对象,调用另一个对象里面的方法,但这样每次都要new对象,会浪费资源,而spring的方式,是在类中声明使用的对象,但是不new,把这个对象和spring容器中对应的对象连接起来,这样的话,声明的对象就指向了spring容器中对象的引用,这样就实现了对象之间的依赖。

代码实现

notion image
image-20230130171621877

结果

notion image
image-20230130171656027
通过属性文件给bean注入值选择器的权重
Loading...