代码编织梦想

包:User

user1.java

package User;

public class User1 {

    private int id;
    private String username;
    private String password;

    public User1() {
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    @Override
    public String toString() {
        return "User1{" +
                "id=" + id +
                ", username='" + username + '\'' +
                ", password='" + password + '\'' +
                '}';
    }
}

包:Test

XmlTest.java

package Test;
import User.User1;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class XmlTest {
    public static void main(String[] args) {

        //获取Spring容器
        var ac = new ClassPathXmlApplicationContext("ApplicationContext.xml");

        User1 USER1 = (User1) ac.getBean("User1");
        System.out.println(USER1);



    }
}

src下:ApplicationContext.xml

ApplicationContext.xml

<?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="User1" class ="User.User1">
         <property name="id" value="001"></property>
         <property name="password" value="12456"></property>
         <property name="username" value="张三"></property>
     </bean>

</beans>
b8124f89bf6481aa772ceebfb9601d74.png

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/qq_64005599/article/details/129602679