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
    本文版权归作者和博客园共有,转载必须给出原文链接,并保留此段声明,否则保留追究法律责任的权利。
  • 相关阅读:
    go通道小案例
    go执行cmd命令并获取输出内容
    vue快速生成二维码
    vue.js数字简化 万转化k显示
    uniapp实现小程序获取用户信息
    实现图片预加载功能
    C# MD5加密字符串方法
    一个封装的 HttpClientHelper
    简易通过队列存储并异步打日志实现
    变量
  • 原文地址:https://www.cnblogs.com/binbingg/p/13835471.html
Copyright © 2011-2022 走看看