这篇文章主要介绍“Spring源码知识点有哪些”,在日常操作中,相信很多人在Spring源码知识点有哪些问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”Spring源码知识点有哪些”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!
1.Spring介绍
Spring是为了解决企业应用开发的复杂性,它提供给Java开发者一个综合的基础框架,让开发者更加关注自身业务实现。非侵入的实现JavaBean,使其在简单性、可测试和松耦合的角度,让任何Java应用都可以从Spring中收益。
2.Spring整体框架图如下
下面用脑图展示整体框架核心功能作用说明:
3.初体验Spring容器使用
A.引入spring的maven依赖
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>3.2.1.RELEASE</version>
<scope>runtime</scope>
</dependency>
B.创建测试实体Bean
public class MyTestBean {
private String testStr = "testStr";
public String getTestStr() {
return testStr;
}
public void setTestStr(String testStr) {
this.testStr = testStr;
}
}
C.使用xml文件在spring容器中,创建bean
<?xml version="1.0" encoding="UTF-8" ?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="myTestBean" class="com.zzx.study.bean.MyTestBean">
</bean>
</beans>
D.对实体Bean进行测试
@SuppressWarnings("deprecation")
public class BeanFactoryTest
{
@Test
public void testSimpleLoad() {
BeanFactory bf = new XmlBeanFactory(new ClassPathResource("spring.xml"));
MyTestBean myTestBean = (MyTestBean) bf.getBean("myTestBean");
Assert.assertEquals("testStr", myTestBean.getTestStr());
}
}
4.简要梳理Spring工作流程
加载声明spring bean对应的xml文件->将xml转化为Document对象->将Document中包含的class对象通过反射实例化并成功装载到spring容器中
到此,关于“Spring源码知识点有哪些”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注亿速云网站,小编会继续努力为大家带来更多实用的文章!
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。
原文链接:https://my.oschina.net/u/1017791/blog/3118238