1.创建对象
2.注入属性
2.1 set注入
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <bean id="user" class="com.cj.spring5.User"></bean> <bean id="book" class="com.cj.spring5.Book"> <property name="name" value="java入门到精通"></property> <property name="price" value="88"></property> </bean> </beans>
package com.cj.spring5; public class Book { private String name; private Integer price; public void setName(String name) { this.name = name; } public void setPrice(Integer price) { this.price = price; } @Override public String toString() { return "Book{" + "name='" + name + '\'' + ", price=" + price + '}'; } }
标签:name,price,private,String,bean,ioc,public,spring5 From: https://www.cnblogs.com/cciscc/p/16597327.html