首先去github上找到这个资源
https://github.com/spring-projects/spring-framework
git clone -b 5.2.x https://github.com/spring-projects/spring-framework.git
等待下载完毕 然后用idea导入这个下载的项目即可
这里选择的是gradle编译的!!!
源码是用gradle编译的不是maven
导入项目之后就等着下载依赖就好了
可能会出现缺少AspectJ 在idea中下载插件即可
依赖下载的特别慢 请耐心的等待
build successful之后就开始搭建测试的案例
新建一个module spring-debug
然后修改build.gradle
plugins {
id 'java'
}
group 'org.springframework'
version '5.2.18.BUILD-SNAPSHOT'
repositories {
mavenCentral()
}
dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0'
implementation(project(":spring-context"))
compile 'org.aspectj:aspectjrt:1.9.7'
compile(project(":spring-beans"))
compile(project(":spring-core"))
compile(project(":spring-context"))
compile(project(":spring-webmvc"))
compile(project(":spring-jdbc"))
compile(project(":spring-orm"))
compile(project(":spring-tx"))
compile(project(":spring-web"))
compile(project(":spring-context-indexer"))
compile(project(":spring-context-support"))
compile(project(":spring-expression"))
compile(project(":spring-instrument"))
compile(project(":spring-jcl"))
compile(project(":spring-jms"))
compile(project(":spring-messaging"))
compile(project(":spring-oxm"))
compile(project(":spring-test"))
compile(project(":spring-webflux"))
compile(project(":spring-websocket"))
// compile(project(":spring-aspects"))
// compile('org.springframework:spring-aspectj:5.2.9')
compile("org.aspectj:aspectjweaver:1.9.6")
compile(project(":spring-aop"))
testCompile group: 'junit', name: 'junit', version: '4.12'
compile("com.alibaba:druid:1.2.4")
compile("mysql:mysql-connector-java:5.1.48")
}
test {
useJUnitPlatform()
}
这里不修改的话 很多地方都不能够引用
创建一个test
public class Test {
public static void main(String[] args) {
ApplicationContext ac = new ClassPathXmlApplicationContext("person.xml");
Person bean = ac.getBean(Person.class);
System.out.println(bean);
}
}
创建一个person类
public class Person {
private Integer id;
private String name;
public Person() {
System.out.println("构造方法");
}
public Person(Integer id, String name) {
this.id = id;
this.name = name;
}
public Person(String name,Integer id) {
this.id = id;
this.name = name;
}
public Person(Integer id) {
this.id = id;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public String toString() {
return "Person{" +
"id=" + id +
", name='" + name + '\'' +
'}';
}
}
创建一个person.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd">
<bean id="person" class="com.yzy.Person" scope="prototype">
<property name="id" value="1"></property>
<property name="name" value="zhangsan"></property>
<constructor-arg name="id" value="1"></constructor-arg>
<constructor-arg name="name" value="lisi"></constructor-arg>
</bean>
</beans>
最后运行效果
ok 大公告成