目录
本文将粗略的搭建一个spring源码的阅读环境,为后面的源码阅读做一个准备。做任何事情不管是有一个完美的或者是不太完美的开头,只要去做了,那么就是一种胜利。
由于spring使用了gradle构建工具,接下来先安装gradle。
从gradle官网下载gradle安装包,打开
将下载的安装包gradle-x.x.x-all.zip解压到当前目录
环境变量配置
配置gradle_home
配置path
打开目录行工具,输入gradle -v
,能看到gradle的版本信息表示安装已经成功
spring在github上的仓库地址是:,本文不会直接去github上去下载源码,网速实在太慢。本文使用的码云上spring仓库的镜像,该镜像每日同步一次,地址是https://gitee.com/mirrors/spring-framework
从git导入项目
填写要克隆的git仓库信息,可以点击右边的【test】按钮测试,等待仓库克隆完成
打开导入的spring项目
.gradle
目录,对于administrator
用户,对应的目录是c:\users\administrator\.gradle
。该目录占用的空间一般比较多,所以在这里将这个目录放到其他的盘中。构建完成后报错如下(只列出了一部分):
... error:(63, 30) java: cannot find symbol symbol: class signature location: class org.springframework.cglib.core.keyfactory ... location: class org.springframework.cglib.proxy.enhancer error:(152, 30) java: cannot find symbol ...
spring未了避免与cglib和objenesis冲突,将cglib和objenesis相关的包重新repack到org.springframework.cglib
和org.springframework.objenesis
包中,这部分的代码没有包含到源码当中。构建之前,可以通过添加gradle任务来解决,见:和https://youtrack.jetbrains.com/issue/idea-160605
解决办法如下:
为了方便编写测试spring的代码,在spring-framework单独新建一个模块my-test
右键spring-framework项目->new->module...
输入artifactid: my-test
添加依赖:api(project(":spring-context"))
为了能让my-test自动导入相关的依赖,在gradle面板中右键spring节点
在my-test模块中编写程序测试
创建myapplication
package com.zfx; import org.springframework.context.applicationcontext; import org.springframework.context.support.classpathxmlapplicationcontext; public class myapplication { public static void main(string[] args) { applicationcontext ac = new classpathxmlapplicationcontext("classpath:applicationcontext.xml"); hello hello = (hello)ac.getbean("hello"); hello.sayhello(); } }
在resources目录下新建applicationcontext.xml
<?xml version="1.0" encoding="utf-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <bean id="hello" class="com.zfx.hello"></bean> </beans>
新建hello
类
package com.zfx; public class hello { public void sayhello() { system.out.println("hello, zhangfengxian"); } }
运行myapplication
,可以看到控制台输出:hello, zhangfengxian
至此整个环境算是搭建好了
如对本文有疑问, 点击进行留言回复!!
nginx 配置Jenkins springboot vue swagger nacos等
网友评论