最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊(cè)

spring6.0.x源碼調(diào)試環(huán)境搭建

2023-04-09 00:48 作者:老劍仙pro  | 我要投稿


# 效果


搭建一個(gè)spring源碼調(diào)試環(huán)境,創(chuàng)建一個(gè)spring-demo模塊,寫一些測(cè)試代碼。



![gh](https://fastly.jsdelivr.net/gh/GitHubXiaoSiyuan/images@main/2023/1680963213000ehfkgc.png)


給源碼添加注釋。


![gh](https://fastly.jsdelivr.net/gh/GitHubXiaoSiyuan/images@main/2023/1680963429000t29unb.png)



給源碼打包


![gh](https://fastly.jsdelivr.net/gh/GitHubXiaoSiyuan/images@main/2023/1680963389000x0la82.png)




# ubantu環(huán)境下搭建spring6.0.x源碼環(huán)境


## 步驟


### 源碼網(wǎng)址


[Spring Framework](https://github.com/spring-projects/spring-framework)



![gh](https://fastly.jsdelivr.net/gh/GitHubXiaoSiyuan/images@main/2023/16799267650003l9kkg.png)



### 下載代碼


fork到自己的GitHub倉(cāng)庫(kù),然后拉代碼


```shell

git clone https://github.com/GitHubXiaoSiyuan/spring-framework-6.0.7.git


代碼拉到 ~/files/projects/kernel_projects/fr

amework 目錄下


```


![gh](https://fastly.jsdelivr.net/gh/GitHubXiaoSiyuan/images@main/2023/16799271110005yp0xa.png)



### gradle下載與配置


#### 下載


https://gradle.org/releases/


gradle/wrapper/gradle-wrapper.properties


找到版本為7.6的 gradle

```

distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip

```


![gh](https://fastly.jsdelivr.net/gh/GitHubXiaoSiyuan/images@main/2023/1679927257000sbqasd.png)



找到 7.6 的版本,點(diǎn)擊下載(注:點(diǎn)擊之后,用迅雷下載很快)


下載鏈接如下(復(fù)制即可觸發(fā)迅雷下載)

```

https://downloads.gradle-dn.com/distributions/gradle-7.6-all.zip

```


![gh](https://fastly.jsdelivr.net/gh/GitHubXiaoSiyuan/images@main/2023/1679927424000fswmw3.png)



#### 解壓


```shell

sudo unzip gradle-7.6-all.zip

```


![gh](https://fastly.jsdelivr.net/gh/GitHubXiaoSiyuan/images@main/2023/1679927947000r5p2g3.png)


![gh](https://fastly.jsdelivr.net/gh/GitHubXiaoSiyuan/images@main/2023/1679927983000wjyh33.png)



#### 配置環(huán)境變量


```shell

# 設(shè)置環(huán)境變量

sudo vi /etc/profile


# 在底部加入這一段

# gradle

export GRADLE_HOME=/home/xiaosy/files/development/gradle-7.6?

export PATH=$NODE_HOME/bin:$PATH


# 變量生效

source /etc/profile


# 設(shè)置讀寫權(quán)限

sudo chmod -R 777 /home/xiaosy/files/development/gradle-7.6/bin


# 查看版本

# 不知道為什么直接 gradle -v 沒用

/home/xiaosy/files/development/gradle-7.6/bin/gradle -v

```


![gh](https://fastly.jsdelivr.net/gh/GitHubXiaoSiyuan/images@main/2023/1679928189000b7pbyu.png)



![gh](https://fastly.jsdelivr.net/gh/GitHubXiaoSiyuan/images@main/2023/1679928401000nvb48a.png)



### idea配置


#### 配置gradle編譯


Tools -> gradle


```

# 路徑

壓縮包放在 /gradle/wrapper/ 目錄下


路徑配置

/home/xiaosy/files/development/gradle-7.6



```


![gh](https://fastly.jsdelivr.net/gh/GitHubXiaoSiyuan/images@main/2023/1679929506000yfnvjm.png)


![gh](https://fastly.jsdelivr.net/gh/GitHubXiaoSiyuan/images@main/2023/1679929584000q7r1fh.png)



#### 下載二進(jìn)制版本


```

https://services.gradle.org/distributions/gradle-7.6-bin.zip

```


![gh](https://fastly.jsdelivr.net/gh/GitHubXiaoSiyuan/images@main/2023/1679934576000u5ojbg.png)





#### jdk


設(shè)置為 jdk17


```shell

# 設(shè)置環(huán)境變量

sudo vi /etc/profile



# 修改jdk路徑

# jdk

export JAVA_HOME=/home/xiaosy/files/development/jdk17/jdk-17.0.6



# 變量生效

source /etc/profile


```



![gh](https://fastly.jsdelivr.net/gh/GitHubXiaoSiyuan/images@main/2023/167998843000008zoai.png)



#### gradle-wrapper.properties修改


打開 gradle/wrapper/gradle-wrapper.properties


將distributionUrld地址替換為本地gradle下載


```

# 修改后

distributionUrl=/home/xiaosy/files/development/gradle-7.6-all.zip

```


![gh](https://fastly.jsdelivr.net/gh/GitHubXiaoSiyuan/images@main/2023/167992913500046fqby.png)




#### build.gradle文件修改


替換國(guó)內(nèi)鏡像



```

repositories {

maven { url "https://maven.aliyun.com/repository/central" }

mavenCentral()

maven {

url "https://repo.spring.io/milestone"

content {

// Netty 5 optional support

includeGroup 'io.projectreactor.netty'

}

}

maven { url "https://repo.spring.io/libs-spring-framework-build" }

if (version.contains('-')) {

maven { url "https://repo.spring.io/milestone" }

}

if (version.endsWith('-SNAPSHOT')) {

maven { url "https://repo.spring.io/snapshot" }

}

}


```



![gh](https://fastly.jsdelivr.net/gh/GitHubXiaoSiyuan/images@main/2023/1679929274000ahqgno.png)



#### setting.gradle文件修改


替換國(guó)內(nèi)鏡像



```

repositories {

maven {

url 'https://maven.aliyun.com/repository/public'

}

maven {

url "https://maven.aliyun.com/repository/google"

}

maven { url "https://maven.aliyun.com/repository/gradle-plugin/" }


gradlePluginPortal()

google()

mavenCentral()

}


```


![gh](https://fastly.jsdelivr.net/gh/GitHubXiaoSiyuan/images@main/2023/1679929287000a6pt3a.png)



#### 注釋


//注釋掉不然會(huì)A build scan was not published as you have not authenticated with server 'ge.spring.io'.


![gh](https://fastly.jsdelivr.net/gh/GitHubXiaoSiyuan/images@main/2023/1679934855000a8g2tu.png)



#### 用idea集成的gradlereload


![gh](https://fastly.jsdelivr.net/gh/GitHubXiaoSiyuan/images@main/2023/1679929316000glnh3d.png)




編譯成功


![gh](https://fastly.jsdelivr.net/gh/GitHubXiaoSiyuan/images@main/2023/1679993513000z742ef.png)



### 新建module


![gh](https://fastly.jsdelivr.net/gh/GitHubXiaoSiyuan/images@main/2023/1680022359000ghwzeq.png)



在新項(xiàng)目的build.gradle下添加對(duì)spring模塊的依賴,這里我先添加了spring-beans 和spring-core的依賴。


```

dependencies {

? ? compile(project(":spring-beans"))

? ? compile(project(":spring-core"))

? ? testCompile group: 'junit', name: 'junit', version: '4.12'

}

```



![gh](https://fastly.jsdelivr.net/gh/GitHubXiaoSiyuan/images@main/2023/16800225050001wj7rf.png)




在新項(xiàng)目的src/main/resource下添加spring-config.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">

<!--把對(duì)象的創(chuàng)建交給spring來管理-->

<bean id="person" class="com.wts.Person">

<property name="id" value="1"></property>

<property name="name" value="zhangsan"></property>

</bean>

</beans>



```



創(chuàng)建測(cè)試bean和啟動(dòng)類


```

public class Person {


private int id;


private String name;


public int getId() {

return id;

}


public void setId(int id) {

this.id = id;

}


public String getName() {

return name;

}


public void setName(String name) {

this.name = name;

}

}



```


```

public class Test {


public static void main(String[] args) {

ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");

Person person = (Person) ac.getBean("person");

System.out.println(person);

}

}


```


## debug


### 1. 更改壓縮包位置


```

The specified Gradle distribution 'file:/home/xiaosy/files/projects/kernel_projects/framework/spring-framework-6.0.7/gradle/wrapper/home/xiaosy/files/development/gradle-7.6-all.zip' does not exist.


```



![gh](https://fastly.jsdelivr.net/gh/GitHubXiaoSiyuan/images@main/2023/1679929394000x48v4x.png)





### 2


設(shè)置文件讀寫權(quán)限


Could not create parent directory for lock file /gradle-7.6/wrapper/dists/gradle-7.6-all/cmg34oui1skho6ogkheeq1oxe/gradle-7.6-all.zip.lck



```

sudo chmod -R 777 ~/files/projects/kernel_projects/framework/spring-framework-6.0.7

```



![gh](https://fastly.jsdelivr.net/gh/GitHubXiaoSiyuan/images@main/2023/1679929679000ku4rli.png)



### 3



Cause: zip file is empty


![gh](https://fastly.jsdelivr.net/gh/GitHubXiaoSiyuan/images@main/2023/1679934236000u3uole.png)




### 4


![gh](https://fastly.jsdelivr.net/gh/GitHubXiaoSiyuan/images@main/2023/1679989129000l2vfdw.png)


解決:


gradle.properties


```

org.gradle.java.home=/home/xiaosy/files/development/jdk17/jdk-17.0.6

```


倆 gradle.properties 都設(shè)置了


![gh](https://fastly.jsdelivr.net/gh/GitHubXiaoSiyuan/images@main/2023/1679989274000kh9zm9.png)



注釋掉這段代碼,然后重寫就不報(bào)錯(cuò)了,純粹的編譯問題


![gh](https://fastly.jsdelivr.net/gh/GitHubXiaoSiyuan/images@main/2023/1679993478000870uh6.png)



#### 參考


1. [Spring 6 源碼編譯和高效閱讀源碼技巧分享](https://blog.51cto.com/u_12386660/5949894),[備份](https://app.yinxiang.com/u/0/client/web#?b=43b768f0-ad67-412d-8d92-93ed2358c674&n=06b896b0-8844-487f-9f6b-ebae35a728fc&s=s59&)

2.?


## 參考


1. [Spring6.0.0源碼閱讀環(huán)境搭建-gradle構(gòu)建編譯](https://blog.csdn.net/m0_37904184/article/details/127945857),[備份](https://app.yinxiang.com/u/0/client/web#?n=2f337807-c141-4572-b386-9d17c060efc1&b=43b768f0-ad67-412d-8d92-93ed2358c674&legacy=p)

2. [Spring源碼深度解析:一、Spring整體架構(gòu)和源碼環(huán)境搭建](https://blog.csdn.net/wts563540/article/details/126686645),[備份](https://app.yinxiang.com/u/0/client/web#?n=08cbcf6c-46aa-40df-90c5-ce4d86a0d040&b=43b768f0-ad67-412d-8d92-93ed2358c674&legacy=p)

3.?


spring6.0.x源碼調(diào)試環(huán)境搭建的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國(guó)家法律
正蓝旗| 兰州市| 抚州市| 宁德市| 聊城市| 会昌县| 宿州市| 榕江县| 天门市| 阿尔山市| 建阳市| 荆门市| 曲阳县| 高雄市| 叶城县| 东至县| 池州市| 延吉市| 冀州市| 上高县| 微博| 宁远县| 武义县| 廉江市| 公安县| 香港 | 东山县| 新龙县| 呼伦贝尔市| 丰城市| 五台县| 金寨县| 栾川县| 准格尔旗| 大连市| 蕉岭县| 察隅县| 呈贡县| 互助| 县级市| 大宁县|