源码地址: https://github.com/spring-projects/spring-framework.git 。
参考:https://www.qinweizhao.com/?p=25 。
预编译 spring-oxm。进入项目路径,执行以下命令编译命令:
gradlew :spring-oxm:compileTestJava
创建 qwz-spring-test 模块
package com.qinweizhao.test.first.bean;
import org.springframework.stereotype.Component;
/**
* @author qinweizhao
* @since 2022/3/17
*/
@Component
public class TestBean {
public void test() {
System.out.println("test 方法执行。。。");
}
}
package com.qinweizhao.test.first.config;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
/**
* @author qinweizhao
* @since 2022/3/17
*/
@Configuration
@ComponentScan("com.qinweizhao.test.**")
public class ContextConfig {
}
package com.qinweizhao.test;
import com.qinweizhao.test.first.bean.TestBean;
import com.qinweizhao.test.first.config.ContextConfig;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
/**
* @author qinweizhao
* @since 2022/3/17
*/
public class TestMain {
public static void main(String[] args) {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ContextConfig.class);
TestBean testBean = (TestBean) context.getBean("testBean");
testBean.test();
}
}
plugins {
id 'java'
}
group 'com.qinweizhao'
version '5.3.17-SNAPSHOT'
repositories {
mavenCentral()
}
dependencies {
implementation(project(":spring-context"))
implementation(project(":spring-instrument"))
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0'
}
test {
useJUnitPlatform()
}
结果
test 方法执行。。。