Spring 源码包导入
- 下图为spring源码导入后的截图
- 为了证明是否导入成功,在
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);
}
}
此时包找不到了.
但是我在 5.1.15.build-snapshot 版本中可以正常使用
gradle 配置截图
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通过观察spring-framework 的
settings.gradle
文件发现需要spring作为项目开头 , 因此修改项目名称即可完成包导入