IDEA阅读spring源码并调试「建议收藏」

IDEA阅读spring源码并调试「建议收藏」阿里云服务器优惠券领取优惠券目标:搭建起Spring源码阅读和代码调试跟踪的环境,顺便建立一个简单的Demo,能够调试Spring的源代码本节,主要介绍一下Spring源码阅读和调试的相关环境搭建,并使用MVN创建一个非常简单的Demo,以便可以跟踪和调试Spring的内核。1、源码的下载Spring的源码可以从GitHub上下载:https://github.com/spri………

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺

阿里云服务器优惠券领取  优惠券

聚会小游戏,大家可以体验下。

IDEA阅读spring源码并调试「建议收藏」

目标:搭建起Spring源码阅读和代码调试跟踪的环境,顺便建立一个简单的Demo,能够调试Spring的源代码

1. 资源准备

jdk版本: 1.8.0_202

IDEA版本: 2020.2.1

aspectj版本: aspectj-1.9.2

sourcetree版本: 3.3.8

2. 源码下载

用sourcetree拉取5.2.x分支

IDEA阅读spring源码并调试「建议收藏」

3. 编译源码

3.1 在spring-framework所在目录执行gradlew build命令

eg: D:\Dev\source\java\spring-framework>gradlew build

3.2 在spring-framework所在目录执行gradlew :spring-oxm:compileTestJava命令

eg: D:\Dev\source\java\spring-framework>gradlew :spring-oxm:compileTestJava

4. 设置IDEA编码

IDEA阅读spring源码并调试「建议收藏」

IDEA阅读spring源码并调试「建议收藏」

5. 导入IDEA

IDEA阅读spring源码并调试「建议收藏」

IDEA阅读spring源码并调试「建议收藏」

6. 设置Project Structure

IDEA阅读spring源码并调试「建议收藏」

7. 设置gradle任意改动自动编译

IDEA阅读spring源码并调试「建议收藏」

8. 对spring-test模块做junit测试

IDEA阅读spring源码并调试「建议收藏」

如果选择了test或testNg可能会报错,编辑一下Edit Configurations

IDEA阅读spring源码并调试「建议收藏」

清除Tasks 

IDEA阅读spring源码并调试「建议收藏」

然后重新执行单元测试,选择junit即可 

9.编码规范

1. 为了能使自己的新建的module与spring的其他module一起编译,需要遵循google的编码规范

2. Code Style

    Code Style · spring-projects/spring-framework Wiki · GitHub

    IntelliJ IDEA Editor Settings · spring-projects/spring-framework Wiki · GitHub

10.搭建调试module

IDEA阅读spring源码并调试「建议收藏」

IDEA阅读spring源码并调试「建议收藏」

IDEA阅读spring源码并调试「建议收藏」

 拷贝spring-test的gradle配置到sping-debug中进行覆盖,并修改描述为Spring Debug

IDEA阅读spring源码并调试「建议收藏」

在spring-debug中创建测试类

IDEA阅读spring源码并调试「建议收藏」

/*
 * Copyright 2002-2020 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.lazy.bean.test;

/**
 * test bean.
 *
 * @author Lazy Hu
 */
public class MyTestBean {

	private String testStr = "testStr";

	public String getTestStr() {
		return this.testStr;
	}

	public void setTestStr(String testStr) {
		this.testStr = testStr;
	}
}

创建bean配置文件

IDEA阅读spring源码并调试「建议收藏」

<?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 https://www.springframework.org/schema/beans/spring-beans.xsd">

	<bean id="myTestBean" class="com.lazy.bean.test.MyTestBean"/>

</beans>

创建测试类

IDEA阅读spring源码并调试「建议收藏」

在测试类中写入测试信息

IDEA阅读spring源码并调试「建议收藏」

/*
 * Copyright 2002-2019 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.lazy.bean.test;

import org.junit.jupiter.api.Test;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;

import static org.assertj.core.api.Assertions.assertThat;

/**
 * Unit tests for {@link MyTestBean}.
 *
 * @author Lazy Hu
 */
class MyTestBeanTests {

	@Test
	void testSimpleLoad() {
		BeanFactory bf = new XmlBeanFactory(new ClassPathResource("beanFactoryTest.xml"));
		MyTestBean bean = (MyTestBean) bf.getBean("myTestBean");
		assertThat(bean.getTestStr()).isEqualTo("testStr");
	}
}

进行debug

IDEA阅读spring源码并调试「建议收藏」

测试结果

IDEA阅读spring源码并调试「建议收藏」

11. 全部模块进行编译

11.1编译

d:
cd Dev\source\java\spring-framework
gradlew build

IDEA阅读spring源码并调试「建议收藏」

11.2编译遇到的问题

IDEA阅读spring源码并调试「建议收藏」

非法导入  org.junit.jupiter.api.Test;

11.3解决办法

路径(源码所放目录): D:\Dev\source\java\spring-framework\src\checkstyle\checkstyle.xml

修改<property name=”regexp” value=”true” />为<property name=”regexp” value=”false” />

<module name="com.puppycrawl.tools.checkstyle.checks.imports.IllegalImportCheck">
	<property name="id" value="bannedJUnitJupiterImports"/>
    <property name="regexp" value="false" />
	<property name="illegalClasses" value="^org\.junit\.jupiter\..+" />
</module>

11.4重新执行编译

IDEA阅读spring源码并调试「建议收藏」

阿里云服务器优惠券领取  优惠券

Spring编码规范

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/170007.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • idea2021永久激活码【2021.7最新】

    (idea2021永久激活码)好多小伙伴总是说激活码老是失效,太麻烦,关注/收藏全栈君太难教程,2021永久激活的方法等着你。IntelliJ2021最新激活注册码,破解教程可免费永久激活,亲测有效,下面是详细链接哦~https://javaforall.net/100143.html65MJGLILER-eyJsaWNlbnNlSWQi…

    2022年3月22日
    51
  • navicat 15激活码(注册激活)

    (navicat 15激活码)2021最新分享一个能用的的激活码出来,希望能帮到需要激活的朋友。目前这个是能用的,但是用的人多了之后也会失效,会不定时更新的,大家持续关注此网站~IntelliJ2021最新激活注册码,破解教程可免费永久激活,亲测有效,下面是详细链接哦~https://javaforall.net/100143.html…

    2022年3月21日
    242
  • idea 自动导入包 快捷键「建议收藏」

    idea 自动导入包 快捷键「建议收藏」IntelliJIDEA自动导入包快捷方式idea可以自动优化导入包,但是有多个同名的类调用不同的包,必须自己手动Alt+Enter设置设置idea导入包勾选标注1选项,IntelliJIDEA将在我们书写代码的时候自动帮我们优化导入的包,比如自动去掉一些没有用到的包。勾选标注2选项,IntelliJIDEA将在我们书写代码的时候自动帮我

    2022年5月21日
    1.6K
  • vmware15激活密钥最新【2021免费激活】

    (vmware15激活密钥最新)好多小伙伴总是说激活码老是失效,太麻烦,关注/收藏全栈君太难教程,2021永久激活的方法等着你。IntelliJ2021最新激活注册码,破解教程可免费永久激活,亲测有效,下面是详细链接哦~https://javaforall.net/100143.html4M7HSKPBXS-eyJsaWNlbnNlSWQi…

    2022年3月29日
    123
  • IntelliJ IDEA 2022 JetbrainsIdesCrack 激活码【2022免费激活】

    (IntelliJ IDEA 2022 JetbrainsIdesCrack 激活码)2021最新分享一个能用的的激活码出来,希望能帮到需要激活的朋友。目前这个是能用的,但是用的人多了之后也会失效,会不定时更新的,大家持续关注此网站~https://javaforall.net/100143.htmlIntelliJ2021最新激活注册码,破解教程可免费永久激活,亲测有效,上面是详细链接哦~HC…

    2022年4月1日
    465
  • jetbrains 免费激活码 2022【最新永久激活】

    (jetbrains 免费激活码 2022)JetBrains旗下有多款编译器工具(如:IntelliJ、WebStorm、PyCharm等)在各编程领域几乎都占据了垄断地位。建立在开源IntelliJ平台之上,过去15年以来,JetBrains一直在不断发展和完善这个平台。这个平台可以针对您的开发工作流进行微调并且能够提供…

    2022年4月1日
    3.2K

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号