spring源码编译
spring版本:v5.2.6.RELEASE1. 克隆spring源码
git clone https://github.com/spring-projects/spring-framework.git
2. 切换版本至
v5.2.6.RELEASE
进入spring-framework下执行
git checkout -b v5.2.6.RELEASE v5.2.6.RELEASE
3. 配置gradle全局下载仓库,为了国内加速下载依赖 对所有项目生效,在~/.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
}
}
}
4. 执行
./gradlew :spring-oxm:compileTestJava
,效果如下 文章图片
效果图 若gradle无法下载可手动下载,放置gradle/wrapper下,然后修改distributionUrl。如图
文章图片
image 5. Idea导入 【spring源码编译】Import Project -> 勾选Gradle -> Finshed
6. 构建自己的Demo工程 6.1 新建工程
文章图片
image 6.2 引入依赖 在build.gradle中加入
dependencies {
compile(project(":spring-context"))
testCompile group: 'junit', name: 'junit', version: '4.12'
}
6.3 编写代码 UserService.class
### interface
public interface UserService {
void sayHello();
}
UserServiceImpl.class
### impl
public class UserServiceImpl implements UserService {
@Override
public void sayHello() {
System.out.println("Hello spring framework.");
}
}
SpringApplication.class
public class SpringApplication {
public static void main(String[] args) {
AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
applicationContext.register(UserServiceImpl.class);
applicationContext.refresh();
UserService userService = applicationContext.getBean(UserService.class);
userService.sayHello();
}
}
6.4 最终效果
文章图片
image
推荐阅读
- Activiti(一)SpringBoot2集成Activiti6
- SpringBoot调用公共模块的自定义注解失效的解决
- 解决SpringBoot引用别的模块无法注入的问题
- Android事件传递源码分析
- 2018-07-09|2018-07-09 Spring 的DBCP,c3p0
- Quartz|Quartz 源码解析(四) —— QuartzScheduler和Listener事件监听
- [源码解析]|[源码解析] NVIDIA HugeCTR,GPU版本参数服务器---(3)
- ffmpeg源码分析01(结构体)
- spring|spring boot项目启动websocket
- Java程序员阅读源码的小技巧,原来大牛都是这样读的,赶紧看看!