zoukankan      html  css  js  c++  java
  • 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
    本文版权归作者和博客园共有,转载必须给出原文链接,并保留此段声明,否则保留追究法律责任的权利。
  • 相关阅读:
    6.1 tar:打包备份
    6.3-4 zip、unzip
    6.5 scp:远程文件复制
    S7 Linux用户管理及用户信息查询命令
    7.6 passwd:修改用户密码
    7.2-5 usermod
    DES
    FreeRTOS笔记
    第4章 裸机系统和多任务系统
    第008课_第1个ARM落版程序及引申
  • 原文地址:https://www.cnblogs.com/binbingg/p/13835471.html
Copyright © 2011-2022 走看看