Spring5框架01-入门案例
一、创建普通类,在这个类创建普通方法
package com.atguigu.spring5;
public class User {
public void add() {
System.out.println("add......");
}
}
二、创建Spring配置文件,在配置文件配置创建的对象
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
</beans>
三、进行测试代码编写
@Test
public void testAdd() {
BeanFactory context =
new ClassPathXmlApplicationContext("bean1.xml");
User user = context.getBean("user", User.class);
System.out.println(user);
user.add();
}
System.out.println(user);
user.add();
}