Spring源码在github上,地址是https://github.com/spring-projects/spring-framework/,选择5.3.x版本,直接从github上克隆项目网速很慢,所以首先将github上的Spring项目导入gitee仓库里,再从gitee克隆项目。
克隆项目后,等待项目构建完毕,时间可能比较长。
新建一个gradle模块myselft-test
在settings.gradle文件加入
include 'myselft-test'
在myselft-test模块build.gradle加入
implementation project(":spring-context")
implementation project(":spring-beans")
在resources目录新建app.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:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<beans>
<bean id="person" class="xml.Person">
<property value="张三" name="name"></property>
</bean>
</beans>
</beans>
新建Person.class
点击查看代码
public class Person {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
测试
点击查看代码
public class Main {
public static void main(String[] args) {
ApplicationContext applicationContext = new ClasspathXmlApplicationContext("classpath:app.xml");
Person person = applicationContext.getBean(Person.class);
System.out.println(person.getName());
}
}
执行结果:
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。