一、Spring框架是一个分层架构,包含一系列的功能要素,大约分为20个模块。这些模块被总结为以下几个部分。
1、Core Container,Core Container包含有Core、Beans、Context和Expression Language模块,为核心容器。
2、Data Access/Integration,该层包含JDBC、ORM、OXM、JMS和Transaction模块。
3、Web,Web上下文模块简历再应用程序上下文模块之上,为基于Web的应用程序提供了上下文。包括Web、Web-Servlet、Web-Struts和Web-Porlet模块。
4、AOP,面相切面编程的实现,可以定义例如方法拦截器和七点,降低逻辑代码的耦合性。
5、Test,支持使用Junit和TestNG对Spring进行测试。
二、环境搭建
1、获取源码,本文以Spring 5.0.x为例。https://github.com/spring-projects/spring-framework/tree/5.0.x
2、使用git clone 至本地。
3、下载gradle,解压到某个文件夹,将bin目录加入到环境变量。
4、切换阿里镜像,在用户目录/.gradle/下新建文件init.gradle,输入如下:
allprojects{
repositories {
def ALIYUN_REPOSITORY_URL = 'http://maven.aliyun.com/nexus/content/groups/public'
def ALIYUN_JCENTER_URL = 'http://maven.aliyun.com/nexus/content/repositories/jcenter'
all {
ArtifactRepository repo ->
if (repo instanceof MavenArtifactRepository) {
def url = repo.url.toString()
if (url.startsWith('https://repo1.maven.org/maven2')) {
project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_REPOSITORY_URL."
remove repo
}
if (url.startsWith('https://jcenter.bintray.com/')) {
project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_JCENTER_URL."
remove repo
}
}
}
maven {
url ALIYUN_REPOSITORY_URL
url ALIYUN_JCENTER_URL
}
}
}
5、编译,到spring-framework路径下执行命令gradle cleanIdea :spring-oxm:compileTestJava
,等待编译完成(注:编译过程中会自动联网下载依赖)。
3、导入开发工具,本文以IDEA为例,选取Gradle构建,因为spring5.0.x是由Gradle构建的。
4、导入后,会自动编译,编译好之后,界面如下: