其他分享
首页 > 其他分享> > spring5 ioc bean管理

spring5 ioc bean管理

作者:互联网

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,Book,ioc,public,spring5
来源: https://www.cnblogs.com/cciscc/p/16597327.html