本篇博客内容:如果类的一个属性是集合时,如何注入这个集合对象?本篇博客就是介绍这些内容;
说明:
(1)注入集合对象还是比较常用的;
(2)在可以使用【value-ref】或者【ref】的地方,都可以支持内置<bean>;
目录
零:为了方便后面演示,创建一个基于maven的项目s05;
readme.md:项目说明文档
通过“公司资产配置清单”案例学习集合类型的注入
pom.xml:
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.imooc.spring</groupId> <artifactId>s05</artifactId> <version>1.0-SNAPSHOT</version> <repositories> <repository> <id>aliyun</id> <name>aliyun</name> <url>https://maven.aliyun.com/repository/public</url> </repository> </repositories> <dependencies> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>5.3.9</version> </dependency> </dependencies> </project>
说明:
(1)没什么好说的,就是设置国内maven仓库;引入spring框架的依赖;
applicationContext.xml:
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XML