- spring是一个为简化企业级开发而生的开源框架
- spring是ioc和aop容器的框架
- ioc全称: Inversion Of Control【控制反转】
- 将对象的控制权由程序员交给spring容器
- ioc全称: Inversion Of Control【控制反转】
- DI全称:Dependency Injection【依赖注入】
- spring管理对象与对象之间的依赖
- aop全称: Aspect-Oriented Programming【面向切面编程】
- 官网 :Spring | Home
- spring简介图
- 导入jar包
org.springframework spring-context5.3.1 junit junit4.12 test -
创建POJO
@Data @AllArgsConstructor @NoArgsConstructor public class Employee { private Integer id; private String lastName; private String email; private Double salary; private Dept dept; -
编写核心配置文件
配置文件名字applicationContext.xml【beans.xml或spring.xml】
位置在src/main/resources
实例代码
-
使用核心类库【容器对象】
@Test public void testSpringHw(){ //创建Spring容器对象 ApplicationContext ioc = new ClassPathXmlApplicationContext("applicationContext.xml"); //通过容器对象,获取需要对象 Employee empCui = (Employee) ioc.getBean("emp2"); System.out.println("empCui = " + empCui); }



