栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

spring和spring-boot源码环境搭建

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

spring和spring-boot源码环境搭建

Spring源码环境搭建 测试环境
  • macOS
  • JDK11
  • Gradle 6.8+
  • spring分支 5.3.x
准备JDK和Gradle

通过oracle官网下载JDK11并安装,~/.zshrc设置环境变量

export JAVA_11_HOME=/Library/Java/JavaVirtualMachines/jdk-11.0.15.1.jdk/Contents/Home
export JAVA_8_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_311.jdk/Contents/Home

alias jdk8='export JAVA_HOME=$JAVA_8_HOME'
alias jdk11='export JAVA_HOME=$JAVA_11_HOME'

Gradle官网 下载并配置环境变量

GRADLE_HOME=/Users/sunhongyue/work/code/3rd/gradle-7.4.2;
export GRADLE_HOME
export PATH=$PATH:$GRADLE_HOME/bin
准备源码

fork spring的官方仓库,并clone到本地

在终端clone的时候最好设置代理,这样会快很多,查看自己的代理配置,并在~/.zshrc添加代理配置

# where proxy
proxy () {
  export all_proxy=http://127.0.0.1:1087
  echo "All Proxy on"
}

# where noproxy
unproxy () {
  unset all_proxy
  echo "All Proxy off"
}

配置好代理之后,速度飞起

spring目前是用Gradle进行构建,相比Maven,Gradle构建大型项目时会快很多

切换新的分支
➜  spring-framework git:(main) git checkout -b  5.3.x.note origin/5.3.x 
Branch '5.3.x.note' set up to track remote branch '5.3.x' from 'origin'.
Switched to a new branch '5.3.x.note'

我们切到自己的分支进行开发和测试。

预编译

根目录下的import-into-idea.md文件给出了步骤,第一步就是预编译
首先安装gradle,版本需要6.8+

gradle -v
gradle :spring-oxm:compileTestJava

这里可能会报错

> Task :spring-core:compileJava
/Users/sunhongyue/work/code/github/java/MySpring2/spring-framework/spring-core/src/main/java/org/springframework/core/CoroutinesUtils.java:74: 警告: [deprecation] AccessibleObject中的isAccessible()已过时
                if (method.isAccessible() && !KCallablesJvm.isAccessible(function)) {
                          ^

这里isAccessible() JDK9之后就弃用了,所以在源码中把这句method.isAccessible() 去掉了,之后就可以成功预编译了

编译成功

➜  spring-framework git:(5.3.x.note) ✗ gradle :spring-oxm:compileTestJava

> Task :spring-beans:compileGroovy
注: /Users/sunhongyue/work/code/github/java/MySpring2/spring-framework/spring-beans/build/tmp/compileGroovy/groovy-java-stubs/org/springframework/beans/factory/groovy/GroovyDynamicElementReader.java使用或覆盖了已过时的 API。
注: 有关详细信息, 请使用 -Xlint:deprecation 重新编译。

> Task :spring-oxm:xjcGenerate
Errors occurred while build effective model from /Users/sunhongyue/.gradle/caches/modules-2/files-2.1/com.sun.xml.bind/jaxb-xjc/2.2.11/4da3d39ae8ccc39549e3f8971f56035f61d7bf79/jaxb-xjc-2.2.11.pom:
    'dependencyManagement.dependencies.dependency.systemPath' for com.sun:tools:jar must specify an absolute path but is ${tools.jar} in com.sun.xml.bind:jaxb-xjc:2.2.11
Errors occurred while build effective model from /Users/sunhongyue/.gradle/caches/modules-2/files-2.1/com.sun.xml.bind/jaxb-core/2.2.11/db0f76866c6b1e50084e03ee8cf9ce6b19becdb3/jaxb-core-2.2.11.pom:
    'dependencyManagement.dependencies.dependency.systemPath' for com.sun:tools:jar must specify an absolute path but is ${tools.jar} in com.sun.xml.bind:jaxb-core:2.2.11
Errors occurred while build effective model from /Users/sunhongyue/.gradle/caches/modules-2/files-2.1/com.sun.xml.bind/jaxb-impl/2.2.11/2d4b554997fd01d1a2233b1529b22fc9ecc0cf5c/jaxb-impl-2.2.11.pom:
    'dependencyManagement.dependencies.dependency.systemPath' for com.sun:tools:jar must specify an absolute path but is ${tools.jar} in com.sun.xml.bind:jaxb-impl:2.2.11

BUILD SUCCESSFUL in 35s
47 actionable tasks: 29 executed, 18 up-to-date

A build scan was not published as you have not authenticated with server 'ge.spring.io'.
添加测试module进行测试

创建一个新的module

build.gradle的dependencies块添加如下内容,引入同级的module

implementation(project(":spring-beans"))
implementation(project(":spring-core"))
implementation(project(":spring-context"))

resource目录下创建spring-config.xml




   
   

创建Hello.java测试

文件开头要添加License信息


package com.hongyi;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Hello {
	public static void main(String[] args) {
		ApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath:spring-config.xml");
		Hello hello = (Hello) applicationContext.getBean("hello");
		hello.test();
	}

	public void test() {
		System.out.println("你好");
	}
}

运行main测试结果

使用gradle构建module

gradle :spring-samples:build

SpringBoot环境搭建 测试环境
  • macOS
  • JDK8+
  • Gradle 6.8+
  • spring-boot分支 2.4.x
准备源码

fork spring-boot的官方仓库

在终端clone的时候同样最好设置代理,设置代理见上文。

切换新的分支
git checkout -b 2.4.x.note origin/2.4.x

我们切到自己的分支进行开发和测试

运行测试程序

Spring-boot工程里给出了很多smoke test,

关于smoke test,这个词语源自硬件行业,可以类比新电路板的基本功能检查(即新电路板焊好之后先进行通电检查,如果存在设计缺陷,电路板可能会因为短路而冒烟)。冒烟测试,也被称为构建验证测试或构建验收测试,它确定一个程序的最关键功能是有效的,但没有深入到更细的细节。冒烟测试是在构建之后和发布之前对软件进行的初步检查。这种类型的测试在关键测试实现之前发现应用程序中的基本和关键问题。

准备好代码之后,用IDEA导入项目,会经历一个下载依赖,build,索引的过程,等就绪后,找到spring-boot-build.spring-boot-tests.spring-boot-smoke-tests.spring-boot-smoke-test-tomcat,这是一个简单的基于tomcat的web程序,默认监听8080端口,运行起来后,浏览器输入http://localhost:8080/ 可验证结果。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/957086.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号