Spring框架入门

本文深入探讨Spring框架的两大核心概念:控制反转(IOC)和面向切面编程(AOP)。通过实例说明如何在应用中实现依赖注入,以及在Spring配置文件中进行实体类的依赖注入,展示了Spring框架的基本使用流程。

知识点:

Spring : 容器
1.两大核心
控制反转IOC:代理的思想 依赖注入
面向切面AOP

因为需要a1对象,所以去new 实例化了
Class A{
a(){print(“123”)}
}

Class B{
b(){
//要调用a()
A a1 = new A();//因为需要a1对象,所以去new 实例化了 想用就实例化注入
a1.a();//想成功的调用到a方法 必须有a1对象,依赖a1
}
}

准备工作:

1.jar包
在这里插入图片描述
2.创建spring配置文件——applicationContext.xml
在这里插入图片描述
代码如下:
< 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
xmlns:util=“http://www.springframework.org/schema/util
xsi:schemaLocation=“http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-3.0.xsd”>

< /beans>

调用举例:

1…创建spring配置文件——applicationContext.xml
在这里插入图片描述
2.创建测试类文件以及UI借口
测试文件A
在这里插入图片描述
测试文件C
在这里插入图片描述
借口文件UI
在这里插入图片描述
测试文件B为主要输出文件
在这里插入图片描述

通过ClassPathXmlApplicationContext("applicationContext.xml"加载applicationContext.xml

2.在applicationContext.xml中依赖注入实体类
在这里插入图片描述
3.在B中检测输出
在这里插入图片描述
测试完成

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值