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)
上一篇 2022年8月12日 上午10:16
下一篇 2022年8月12日 上午10:36


相关推荐

  • navicat premium 15 激活码_在线激活

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

    2022年3月26日
    281
  • IntelliJ IDEA调整字体大小

    IntelliJ IDEA调整字体大小IntelliJIDEA 开发工具默认的代码字体大小是 12 看起来比较小 不是很舒服 下面介绍是解决 IntelliJIDEA 开发工具代码字体太小的解决方法 工具 原料 IntelliJIDEA 方法 步骤 首先双击桌面图标 打开 IntelliJIDEA 开发工具 选择单击菜单栏 Flie Settings 设置弹出 Settings 对话框

    2026年3月19日
    2
  • phpstorm 激活码 2021 3月最新注册码

    phpstorm 激活码 2021 3月最新注册码,https://javaforall.net/100143.html。详细ieda激活码不妨到全栈程序员必看教程网一起来了解一下吧!

    2022年3月14日
    77
  • Idea激活码永久有效Idea2020.2.4激活码教程-持续更新,一步到位[通俗易懂]

    Idea激活码永久有效Idea2020.2.4激活码教程-持续更新,一步到位[通俗易懂]Idea激活码永久有效2020.2.4激活码教程-Windows版永久激活-持续更新,Idea激活码2020.2.4成功激活

    2022年6月17日
    116
  • idea激活码7天[免费获取]

    (idea激活码7天)本文适用于JetBrains家族所有ide,包括IntelliJidea,phpstorm,webstorm,pycharm,datagrip等。IntelliJ2021最新激活注册码,破解教程可免费永久激活,亲测有效,下面是详细链接哦~https://javaforall.net/ide…

    2022年3月22日
    141
  • webstorm 2022激活码_在线激活

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

    2022年3月31日
    892

发表回复

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

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