Spring 源码包导入

发布于 2022-09-12 02:31:29 字数 4998 浏览 24 评论 0

  • 下图为spring源码导入后的截图

image.png

  • 为了证明是否导入成功,在spring-context子工程中添加了如下测试代码
package org.springframework;

import org.springframework.validation.AbstractErrors;

public class Test {
    public static void main(String[] args) {
        System.out.println(AbstractErrors.NESTED_PATH_SEPARATOR);
    }
}

启动结果:

10:03:41 下午: Executing task 'Test.main()'...

> Task :buildSrc:compileJava UP-TO-DATE
> Task :buildSrc:compileGroovy NO-SOURCE
> Task :buildSrc:pluginDescriptors UP-TO-DATE
> Task :buildSrc:processResources UP-TO-DATE
> Task :buildSrc:classes UP-TO-DATE
> Task :buildSrc:jar UP-TO-DATE
> Task :buildSrc:assemble UP-TO-DATE
> Task :buildSrc:pluginUnderTestMetadata UP-TO-DATE
> Task :buildSrc:compileTestJava NO-SOURCE
> Task :buildSrc:compileTestGroovy NO-SOURCE
> Task :buildSrc:processTestResources NO-SOURCE
> Task :buildSrc:testClasses UP-TO-DATE
> Task :buildSrc:test NO-SOURCE
> Task :buildSrc:validateTaskProperties UP-TO-DATE
> Task :buildSrc:check UP-TO-DATE
> Task :buildSrc:build UP-TO-DATE
> Task :wrapper

BUILD SUCCESSFUL in 2s
1 actionable task: 1 executed
> Task :buildSrc:compileJava UP-TO-DATE
> Task :buildSrc:compileGroovy NO-SOURCE
> Task :buildSrc:pluginDescriptors UP-TO-DATE
> Task :buildSrc:processResources UP-TO-DATE
> Task :buildSrc:classes UP-TO-DATE
> Task :buildSrc:jar UP-TO-DATE
> Task :buildSrc:assemble UP-TO-DATE
> Task :buildSrc:pluginUnderTestMetadata UP-TO-DATE
> Task :buildSrc:compileTestJava NO-SOURCE
> Task :buildSrc:compileTestGroovy NO-SOURCE
> Task :buildSrc:processTestResources NO-SOURCE
> Task :buildSrc:testClasses UP-TO-DATE
> Task :buildSrc:test NO-SOURCE
> Task :buildSrc:validateTaskProperties UP-TO-DATE
> Task :buildSrc:check UP-TO-DATE
> Task :buildSrc:build UP-TO-DATE
> Task :spring-expression:processResources
> Task :spring-aop:processResources
> Task :spring-core:cglibRepackJar FROM-CACHE
> Task :spring-core:objenesisRepackJar FROM-CACHE
> Task :spring-beans:processResources
> Task :spring-core:processResources NO-SOURCE
> Task :spring-context:processResources
> Task :spring-instrument:compileJava FROM-CACHE
> Task :spring-instrument:processResources NO-SOURCE
> Task :spring-instrument:classes UP-TO-DATE
> Task :spring-instrument:jar
> Task :spring-jcl:compileJava FROM-CACHE
> Task :spring-jcl:processResources
> Task :spring-jcl:classes
> Task :spring-jcl:jar
> Task :kotlin-coroutines:compileKotlin FROM-CACHE
> Task :kotlin-coroutines:compileJava NO-SOURCE
> Task :kotlin-coroutines:processResources NO-SOURCE
> Task :kotlin-coroutines:classes UP-TO-DATE
> Task :kotlin-coroutines:inspectClassesForKotlinIC
> Task :kotlin-coroutines:jar
> Task :spring-core:compileKotlin FROM-CACHE
> Task :spring-core:compileJava FROM-CACHE
> Task :spring-core:classes UP-TO-DATE
> Task :spring-core:inspectClassesForKotlinIC
> Task :spring-core:jar
> Task :spring-expression:compileKotlin FROM-CACHE
> Task :spring-expression:compileJava FROM-CACHE
> Task :spring-expression:classes
> Task :spring-expression:inspectClassesForKotlinIC
> Task :spring-expression:jar
> Task :spring-beans:compileGroovy
> Task :spring-beans:compileGroovy FROM-CACHE
> Task :spring-beans:compileKotlin
> Task :spring-beans:compileJava NO-SOURCE
> Task :spring-beans:classes
> Task :spring-beans:inspectClassesForKotlinIC
> Task :spring-beans:jar
> Task :spring-aop:compileJava
> Task :spring-aop:compileJava FROM-CACHE
> Task :spring-aop:classes
> Task :spring-aop:jar
> Task :spring-context:compileKotlin
> Task :spring-context:compileJava
> Task :spring-context:compileGroovy NO-SOURCE
> Task :spring-context:classes

> Task :spring-context:Test.main()
.

BUILD SUCCESSFUL in 2m 0s
31 actionable tasks: 20 executed, 11 from cache
10:05:44 下午: Task execution finished 'Test.main()'.

输出了内容. 因此认为spring 源码环境搭建成功,但是在创建子项目后创建测试用例

public class Demo {
    public static void main(String[] args) {
        BeanFactory beanFactory = new ClassPathXmlApplicationContext("META-INF/dependency.xml");
        UserEntity bean = beanFactory.getBean(UserEntity.class);
        System.out.println(bean);
    }
}

image.png
此时包找不到了.
但是我在 5.1.15.build-snapshot 版本中可以正常使用

gradle 配置截图
image.png

build.gradle

plugins {
    id 'java'
}

group 'org.springframework'
version '5.2.3.RELEASE'

repositories {
    mavenCentral()
}

dependencies {
    compile(project(":spring-beans"))
    compile(project(":spring-core"))

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦回旧景 2022-09-19 02:31:29
rootProject.name = "spring"
rootProject.children.each {project ->
    project.buildFileName = "${project.name}.gradle"
}

通过观察spring-framework 的settings.gradle文件发现需要spring作为项目开头 , 因此修改项目名称即可完成包导入

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文