1 spring框架概念2 spring框架的基本架构图3 spring框架-hello world
3.1 创建maven项目3.2 引入依赖:spring框架3.3 定义一个类3.4 配置spring容器3.5 实现
1 spring框架概念Spring框架是一个开放源代码的J2EE应用程序框架,是针对bean的生命周期进行管理的轻量级容器(容器可以理解为管理应用程序的java代码)Spring提供了功能强大的IOC、AOP及WebMVC等功能。 2 spring框架的基本架构图
3 spring框架-hello world 3.1 创建maven项目 3.2 引入依赖:spring框架 3.3 定义一个类@Data
@AllArgsConstructor
@NoArgsConstructor
public class Car {
private Integer id;
private String brand;
private String color;
private Double price;
}
3.4 配置spring容器
3.5 实现
@Test
public void testOld() {
Car c = new Car(2, "奔驰", "黑色", 666666.00);
System.out.println(c);
}
@Test
public void testNew() {
// 获取spring容器
ApplicationContext act =
new FileSystemXmlApplicationContext("classpath:spring/appContext.xml");
// 获取bean,通过刚才设置的bean的id:car,生成Car类型的对象
Car bean = act.getBean(Car.class,"car");
System.out.println(bean);
}



