白话Spring源码(三):spring框架的理解

一、为什么需要Spring

我们想一下如果没有spring框架我们是怎么去开发web应用呢?

我估计大部分代码是跟业务无关而跟底层或者网络接口交互;对象,模块关系错综复杂;开发周期特别的长很容易流产;后期维护时代码会越来越烂,最后可能无法维护。。。

那spring框架给我们解决什么问题了呢?

1.封装非业务的代码,我们只需开发业务功能:比如获取请求的数据,保存数据库,事务等等

2.统一创建对象,维护对象的关系和生命周期

3.方便的对方法加入通用的代码

4.简化与其他框架的结合使用

总的来说就是为了简化我们企业应用开发的难度,让我们只关注业务功能的开发!

据说开发spring框架是大神也是一位音乐家,所以我们会发现他写的代码很有艺术感,哈哈哈。。。

二、Spring框架的定义

Spring is a layered Java/J2EE application framework, based on code published in "Expert One-on-One J2EE Design
and Development" by Rod Johnson (Wrox, 2002). Spring includes:

* Powerful JavaBeans-based configuration management, applying Inversion-of-Control principles. This makes
wiring up applications quick and easy. No more singletons littered throughout your codebase, no more arbitrary
properties files: one consistent and elegant approach everywhere. This core bean factory can be used in any
environment, from applets to J2EE containers.

* Generic abstraction layer for transaction management, allowing for pluggable transaction managers, and making
it easy to demarcate transactions without dealing with low-level issues. Generic strategies for JTA and a
single JDBC DataSource are included. In contrast to plain JTA or EJB CMT, Spring's transaction support is not
tied to J2EE environments.

* JDBC abstraction layer that offers a meaningful exception hierarchy (no more pulling vendor codes out of
SQLException), simplifies error handling, and greatly reduces the amount of code you'll need to write.
You'll never need to write another finally block to use JDBC again. The JDBC-oriented exceptions comply to
Spring's generic DAO exception hierarchy.

* Integration with Hibernate, JDO, and iBATIS SQL Maps: in terms of resource holders, DAO implementation
support, and transaction strategies. First-class Hibernate support with lots of IoC convenience features,
addressing many typical Hibernate integration issues. All of these comply to Spring's generic transaction
and DAO exception hierarchies.

* AOP functionality, fully integrated into Spring configuration management. You can AOP-enable any object managed
by Spring, adding aspects such as declarative transaction management. With Spring, you can have declarative
transaction management without EJB... even without JTA, if you're using a single database in Tomcat or another
web container without JTA support.

* Flexible MVC web application framework, built on core Spring functionality. This framework is highly configurable
via strategy interfaces, and accommodates multiple view technologies like JSP, Tiles, Velocity, FreeMarker, iText,
and POI. Note that a Spring middle tier can easily be combined with a web tier based on any other web MVC framework,
like Struts, WebWork, or Tapestry.

You can use all of Spring's functionality in any J2EE server, and most of it also in non-managed environments.
A central focus of Spring is to allow for reusable business and data access objects that are not tied to specific
J2EE services. Such objects can be reused across J2EE environments (web or EJB), standalone applications, test
environments, etc without any hassle.

Spring has a layered architecture; all its functionality builds on lower levels. So you can e.g. use the
JavaBeans configuration management without using the MVC framework or AOP support. But if you use the web MVC
framework or AOP support, you'll find they build on the configuration framework, so you can apply your knowledge
about it immediately.

上面是spring的开发者Rod Johnson对spring的介绍,为什么我贴出英文的呢?因为很多翻译过来的就变味了,我们程序员还是要坚持看英文原版的一些概念的解释,这样会更好的去理解作者的本意。

三、spring架构

 

从这张官方的架构图种我们可以看出,spring Core是其他模块的基础,也是spring的核心模块,各模块的作用如下:

* "spring-core" (~185 KB)
- Contents: bean container, core utilities
- Dependencies: Commons Logging, (Log4J)

* "spring-aop" (~110 KB)
- Contents: AOP framework, source-level metadata support
- Dependencies: spring-core, AOP Alliance, (CGLIB, Commons Attributes)

* "spring-context" (~160 KB)
- Contents: application context, validation framework, UI support, JNDI, mail, EJB, remoting, scheduling
- Dependencies: spring-core, (Velocity, FreeMarker, JavaMail, EJB, JAX-RPC, Hessian, Burlap, Quartz)

* "spring-dao" (~175 KB)
- Contents: DAO support, transaction infrastructure, JDBC support
- Dependencies: spring-core, (spring-aop, JTA)

* "spring-orm" (~110 KB)
- Contents: Hibernate support, JDO support, iBATIS SQL Maps support
- Dependencies: spring-dao, (Hibernate, JDO, iBATIS SQL Maps)

* "spring-web" (~70 KB)
- Contents: web application context, multipart resolver, web utilities
- Dependencies: spring-context, Servlet, (Commons FileUpload, COS)

* "spring-webmvc" (~135 KB)
- Contents: web MVC framework, web controllers, web views
- Dependencies: spring-web, (JSP, JSTL, Tiles, iText, POI)

四、spring1.0源码地址

https://gitee.com/haoxin963/spring-framework-1.0

大家可以去下载,开始学习spring源码之旅吧!

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

haoxin963

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值