1 本文核心内容来自 https://docs.spring.io/spring/docs/5.2.1.RELEASE/spring-framework-reference/core.html
2 在我自己阅读文档并写出test后,为了提高本文的可读性,我决定本文不按照spring文档目录顺序排版。将IOC部分拆分为 注册bean,为bean注入属性,spring的其他特性三个方面。
3 文章中所包含的test都经过测试。git地址为
4 文章中对于spring的使用方式和使用技巧,仅代表我个人。如有错误,或不足,请留言。
5 文章环境为jdk8,springboot2.2.2.RELEASE
5 文章适用于使用过spring系列框架的朋友,或者准备学习spring的朋友。
<?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"> <!-- class:哪个bean需要被注册,就用哪个bean的路径 id:告诉spring被注册这个bean叫什么名字--> <bean class="com.datang.springcode.xmlRegisterBean.Computer" id="computer"></bean> </beans>
package com.datang.springcode.annoRegisterBean; import org.springframework.stereotype.Component; //@Component标识这个类,需要被注册 @Component public class Pear { }
package com.datang.springcode.javaRegisterBean; //需要被注册的bean public class Banana { }
package com.datang.springcode.javaRegisterBean; import org.springframework.context.annotation.Bean; public class RegisterBeanConfig { //这个注解才是真正的java注册bean的关键。 @Bean public Banana getBanana(){ return new Banana(); } }
spring-framework-core-ioc Container
原文:https://www.cnblogs.com/zumengjie/p/12058924.html