Spring 的Core模块

本文详细介绍了Spring的Core模块,包括核心容器、BeanFactory、Bean配置及依赖注入。Core模块由Beans、Core和Context等构成,提供IoC和DI功能。通过BeanFactory实例化Bean,配置Bean的基本属性、依赖关系以及高级特性。此外,文章还讨论了属性自动装配、依赖检查以及如何使用PropertyOverrideConfigurer进行属性覆盖。
摘要由CSDN通过智能技术生成

回到首页☞

Core模块主要的功能是实现了反向控制IOC(Inversion of Control)与依赖注入DI(Dependency Injection)、Bean配置以及加载。Core模块中有Beans、BeanFactory、BeanDefinitions、ApplicationContext等几个重要概念。

Beans为Spring里的各种对象,一般要配置在Spring配置文件中:BeanFactory为创建Beans的Factory,Spring通过BeanFactory加载各种Beans;BeanDefinition为Bean在配置文件中的定义,一般要定义id与class:ApplicationContext代表配置文件。

这些类都位于org.springframework.beans和org.springframework.context中。这是Spring最核心的包。Core模块依赖于Spring的Core类库。
在这里插入图片描述
任何框架的核心是依赖关系,和资源有哪些是核心。
码农都有一个问题,在实际项目中玩的很溜,因为框架都是搭建好的,一般一个系统出了前几天搭建后续大家都是在自己的业务模块开发。所以,0-1才是真正的核心。

1、整体了解

1.1、Core Container 核心容器

容器是Spring的核心部分,Core Container 模块是Spring框架的基础,所有模块都构建于核心模块之上。

  • Beans : Beans模块是所有应用都要用到的,它包含访问配置文件、创建和管理bean以及进行Inversion of Control / Depen-dency Injection(IoC/DI)操作相关的所有类。

  • Core : Core模块主要包含Spring框架基本的核心工具类,Spring的其他组件要都要使用到这个包里的类,Core模块是其他组件的基本核心。当然你也可以在自己的应用系统中使用这些工具类。

  • Context : Spring的上下文即IoC容器,通过上下文可以获得容器中的Bean。 ApplicationContext接口是Context模块的关键。 Context模块构建于Core和Beans模块基础之上,提供了一种类似于JNDI注册器的框架式的对象访问方法。

  • SpEl : Expression Language模块提供了一个强大的表达式语言用于在运行时查询和操纵对象。

1.2、 Core Container 依赖关系

在这里插入图片描述
因为spring-core依赖了commons-logging,而其他模块都依赖了spring-core,所以整个spring框架都依赖了commons-logging。
如依赖关系Spring离不开日志,但是日志框架有多种也不一定使用commons-logging如果有自己的日志实现如log4j,可以排除对commons-logging的依赖,没有日志实现而排除了commons-logging依赖,编译报错。

1.3、构建最基础的Spring项目

1.3.1、核心容器四个包

spring-beans-4.1.3.RELEASE.jar
spring-context-4.1.3.RELEASE.jar
spring-core-4.1.3.RELEASE.jar
spring-expression-4.1.3.RELEASE.jar

1.3.2、核心容器依赖的日志包

commons-logging-1.2.jar
log4j-1.2.17.jar
commons-logging相当于一个日志接口,log4j相当于该接口的实现,如果不添加log4j包也可以,因为commons-logging也有一个简单的实现会自动使用。

1.3.3、测试类包

spring-test-4.1.3.RELEASE.jar
junit-4.10.jar(高于4.10版本还需要hamcrest-core.jar + hamcrest-library.jar)

1.3.4、测试类用到了AOP必须导入aop包

spring-aop-4.1.3.RELEASE.jar

1.3.5、pom

目前都是玩的Mavn,搜索对应包就可以找到坐标

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>groupId</groupId>
    <artifactId>myspring</artifactId>
    <version>1.0-SNAPSHOT</version>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <spring-version>5.0.2.RELEASE</spring-version>
    </properties>
    <dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.10</version>
        <scope>test</scope>
    </dependency>
    <!-- Spring核心模块 -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-beans</artifactId>
        <version>${
   spring-version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>${
   spring-version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context-support</artifactId>
        <version>${
   spring-version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>${
   spring-version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-expression</artifactId>
        <version>${
   spring
  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值