Spring框架的整理
来源:互联网 发布:txt数据导入origin 编辑:程序博客网 时间:2024/06/06 01:49
一:核心
(1):IOC 控制反转
(2):AOP 面向切面
二:优点
(1):方便解耦,简化开发(把对象的创建和依赖关系的维护交给Spring)
(2):对AOP的支持,实现拦截,监控,事务管理等功能
(3):Junit4的支持(测试类 @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration("classpath:applicationContext.xml"))
(4):支持各种框架的整合
(5):对部分难用的API做了封装,如JDBC,JavaMail,远程调用等
三:关于applicationContext
(1):ClassPathXmlApplicationContext 加载类路径下的Spring的配置文件
(2):FileSystemXMLApplicationContext 加载本地磁盘下的Spring的配置文件
四:Beanfactory和ApplicationContext的区别
Beanfactory在getBean的时候才会生成类的实例
ApplicationContext在加载ApplicationContext.xml时就创建
五:Bean 的属性
id(唯一 ,不能有特殊符号)
name(可以有特殊符号,整合Struts框架的时候会用到)
class
scope(默认情况下是单例模式singleton prototype是多利)
生命周期的方法init和dsetory
六:DI注入
(1):构造方法注入:constructor-arg name value 当为对象用ref
(2):set方法注入:property name value 当为对象用ref
(3):名称空间P的属性注入方式
(一):引入P名称空间(schema约束)
(二):使用p名称空间 格式:普通属性 p:属性名=" " 对象类型属性 p:属性-ref=" "
(4):SPEL方式的属性注入
语法 #{SPEL }
(5):复杂类型注入
例如:数组;List集合;map集合;properties的注入等
<property name="strings"><array><value>aa</value><value>bb</value></array></property><property name="list"><list><value>中国</value><value>大地</value></list></property><property name="set"><set><value>东邪</value><value>西毒</value><value>南帝</value><value>北丐</value></set></property><property name="map"> <map > <entry key="张翠山" value="1"></entry> <entry key="张无忌" value="2"></entry> </map></property> <!-- 给属性集合文件赋值 --> <property name="properties"> <props > <prop key="杨过">郭襄</prop> <prop key="小龙女">绿鄂</prop> </props> </property>
七:关于多个Spring配置文件的解决方案
(1): ClassPathXmlApplicationContext(“applicationContext1.xml ”,“ applicationContext2.xml ”)
(2):或者采用包含的方式<import resource="配文件"></import>
八:Spring在各个层的注解
在类上的注解:@component(value=" ") 是在xml中注册对象时所对应的id
web层:@controller
service层:@service
持久层:@Repository
属性注入的注解(可以不用提供set方法)
@Autowired
@Qualifer(“属性名”)
关于生命周期配置的注解
@postConstruct 相当于init-method
@preDestory 相当于destory-method
九:AOP面向切面的编程(通过预编译方式和运行期动态代理实现程序功能的统一维护)
在不修改源码的情况下,对程序进行增强
AOP进行权限校验,日志,记录,性能等的监控,事务的控制
底层采用代理机制
(一):JDK动态代理,针对实现了接口的类进行代理
(二):Cglib的动态代理,针对没有实现接口的类产生代理,应用的是底层的字节码增强的技术,生成当前类的子类对象
十:AOP的相关术语
连接点:目标类中的所有方法(Spring只支持方法类型的连接点)
切入点:需要被增强的方法
通知类:公共模块的能力
目标类:服务层的类
织入:通知应用到目标创建代理类的过程,是一个虚拟的过程
代理类:整合目标类和通知类
切面:通知和切入点关联就叫切面
备注:通知的类型(前置,后置和环绕)和切入点的表达式 execution()
十一:AspectJ的AOP注解
@After @AfterReturning @Around
关于它的xml配置为
<!-- AOP编程: aspectj的方式--> <aop:config><!-- aspectj的单独节点 :关联到aspectj的通知--> <aop:aspect ref="myAspect"><!-- 定义切入点 --> <aop:pointcut expression="execution(* com.qf.service.*.*(..))" id="mpPoint"/><!-- aspectj的通知 method=""写的是自定义的方法名称--><!-- <aop:before method="befor" pointcut-ref="mpPoint"/> --><aop:after-returning method="after" returning="res" pointcut-ref="mpPoint"/><!-- <aop:around method="round" pointcut-ref="mpPoint"/> --></aop:aspect> </aop:config>
若有错误的地方或不足的地方,请多多指教,谢谢!!!
- Spring框架的整理
- 整理学习的框架(2)--mybatis+spring
- Java Spring 框架整理
- volly框架的整理
- Struts + Spring + Hibernate 框架资源--整理
- Struts + Spring + Hibernate 框架资源--整理
- Struts + Spring + Hibernate 框架资源--整理
- Struts + Spring + Hibernate 框架资源--整理
- Struts + Spring + Hibernate 框架资源--整理
- WebService框架整理(二) Axis1+Spring
- WebService框架整理(二) Axis1+Spring
- Spring框架内容整理(一):IOC
- Spring框架内容整理(二):DI
- Spring框架内容整理(三):AOP
- Spring的一些整理
- 用struts 和 Spring 框架实现数据的CRUD操作 整理一下!
- Spring学习-35:SSH框架整合之jar包的整理
- SSH框架(四) Spring、Spring MVC、Struts2优缺点整理
- Varnish实现缓存、后端负载均衡和状态检测
- 暑假英语晨读总结
- 2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛-A. Banana
- 【C#】进程和线程
- HashMap和ArrayMap的区别
- Spring框架的整理
- 在Ubuntu环境下配置Hadoop伪分布式模式运行环境
- 划水
- [cocos2dx_Lua]自定义本地化数据
- PHP的SESSION导致长连接阻塞
- 分析HashCode
- python设计模式之迭代器
- 使用公式C=(5/9)(F-32)打印下列华氏温度与摄氏温度对照表。
- 2017年第五届北京大数据与分析创新峰会将于11月在北京召开