软件编程
位置:首页>> 软件编程>> java编程>> 解读Spring-Context的作用及用法

解读Spring-Context的作用及用法

作者:冰点契约丶  发布时间:2023-09-27 06:45:02 

标签:Spring,Context

Spring-Context的作用

spring-context提供应用程序上下文,这是Spring的依赖注入容器,

它可能总是在以某种方式使用Spring Framework的工件的POM中定义.

实际上,spring-context依赖于spring-core,因此通过将spring-context定义为依赖项,

您的类路径中也会包含spring-core.

框架源码 Spring context

应用上下文

Spring通过应用上下文(Application Context)装载bean的定义并把它们组装起来。

Spring应用上下文全权负责对象的创建和组装。

Spring自带了多种应用上下文的实现,它们之间主要的区别仅仅在于如何加载配置。

1.AnnotationConfigApplicationContext:从一个或多个基于Java的配置类中加载 Spring应用上下文。

2.AnnotationConfigWebApplicationContext:从一个或多个基于Java的配置类中 加载Spring Web应用上下文。

3.ClassPathXmlApplicationContext:从类路径下的一个或多个XML配置文件中加 载上下文定义,把应用上下文的定义文件作为类资源。

4.FileSystemXmlapplicationcontext:从文件系统下的一个或多个XML配置文件 中加载上下文定义。

5.XmlWebApplicationContext:从Web应用下的一个或多个XML配置文件中加载上下 文定义。

解读Spring-Context的作用及用法

解读Spring-Context的作用及用法

FileSystemXmlApplicationContext和ClassPathXmlApplicationContext区别

FileSystemXmlApplicationContext在指定的文件系 统路径下查找knight.xml文件;

而ClassPathXmlApplicationContext是在所有的类路径 (包含JAR文件)下查找 knight.xml文件。

来源:https://blog.csdn.net/qq_52751442/article/details/123310077

0
投稿

猜你喜欢

手机版 软件编程 asp之家 www.aspxhome.com