spring-framework-core-ioc Container

  1. xml方式注册bean

  2. java方式注册bean

  3. 注解方式注册bean

  4. ClassPathXmlApplication和AnnotationConfigApplicationContext

  5. 选取哪一种方式合适?

  6. id不可重复

  7. 默认的id

  • 注入属性

  • 特性和功能

阅读须知

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 文章适用于使用过spring系列框架的朋友,或者准备学习spring的朋友。

注册bean

1 xml方式注册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">
    <!-- class:哪个bean需要被注册,就用哪个bean的路径
         id:告诉spring被注册这个bean叫什么名字-->
    <bean class="com.datang.springcode.xmlRegisterBean.Computer" id="computer"></bean>
</beans>
View Code

猜你喜欢

转载自www.cnblogs.com/zumengjie/p/12058924.html