• Spring IoC容器 XML 配置与加载


    IoC 容器 XML 配置文件

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    	xmlns:p="http://www.springframework.org/schema/p"
    	xmlns:context="http://www.springframework.org/schema/context"
    	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-3.0.xsd
         http://www.springframework.org/schema/context
         http://www.springframework.org/schema/context/spring-context-3.0.xsd">
     
    </beans>
    

    加载 IoC 容器 XML 配置文件

    有三种方式可以加载 IoC 容器,如下:

    • ClassPathXmlApplication(相对路径)

    从类路径下的 XML 配置文件中加载上下文定义,把应用上下文定义文件当做类资源

    ApplicationContext ctx = new ClassPathXmlApplicationContext(“包路径/beans.xml”)
    
    
    • FileSystemXmlApplicationContext(绝对路径)

    读取文件系统下的 XML 配置文件并加载上下文定义

    ApplicationContext ctx = new FileSystemtXmlApplicationContext(“文件路径/beans.xml”)
    
    • XmlWebApplicationContext(web 项目配置路径)

    读取 Web 应用下的 XML 配置文件并自动加载,无需手动写加载代码

    作者:Binge
    本文版权归作者和博客园共有,转载必须给出原文链接,并保留此段声明,否则保留追究法律责任的权利。
  • 相关阅读:
    char类型细节
    Hibernate面试题
    线程
    IO流
    集合
    链表相关的一点东西
    正则表达式学习
    python中的变量域问题
    python的输出和输入形式
    python mutable 和 immutable
  • 原文地址:https://www.cnblogs.com/binbingg/p/13835471.html
Copyright © 2020-2023  润新知