什么是Spring
概念
Spring是一个开源框架;
Spring是为了简化企业级应用而生的,使用Spring可以使简单的JavaBean实现EJB(Enterprice Java Bean)才能实现的功能。
特点
- 轻量级
- 依赖注入
- 面向切面编程
- 容器
- 一站式
Spring中最重要的两个概念:IOC(Spring的容器)、AOP(面向切面编程)
核心容器
- Beans (在IOC容器中,所有的类都看作JavaBean)
- Core
- Context (上下文,就是.xml文件)
- SpEL (Spring 中的EL 表达式,简化代码)
IOC容器的基本使用
下面以代码为例,解释IOC容器的基本使用
//Main方法
public class Main {
public static void main(String[] args){
ApplicationContext ioc = new ClassPathXmlApplicationContext("config/applicationContext.xml");
/*创建一个Spring IOC容器
ApplicationContext :IOC容器的类型
ClassPathXmlApplicationContext:IOC容器的构造方法
"config/applicationContext.xml":这里写上配置上下文文件的路径
*/
Apple apple0 =</