配置 Spring.NET
一、编程方式的容器
public class Person
{public string Name { set; get; }public override string ToString(){return "This is Person.";}
}public class Student:Person
{public string School { set; get; }public override string ToString(){return "This is Student.";}
}class Program
{static void Main(string[] args){// 创建容器Spring.Context.Support.StaticApplicationContext context= new Spring.Context.Support.StaticApplicationContext();// 注册context.RegisterPrototype("Person", typeof(Student), null);// 注册一个单例类型context.RegisterSingleton("Alice", typeof(Person), null);Person person = context.GetObject("Person") as Person;Console.WriteLine(person);}
}
二、Xml 方式容器
<objects xmlns="http://www.springframework.net">
<object id="Person" type="Student"></object>
<object id="Alice" type="Person"></object>
</objects>
Spring.Context.Support.XmlApplicationContext context= new Spring.Context.Support.XmlApplicationContext("objects.xml");
Person person = context.GetObject("Person") as Person;Console.WriteLine(person);
三、通过应用程序配置文件来自动加载 Spring.NET 配置
<configuration>
<configSections>
<sectionGroup name="spring">
<section name="context" type="Spring.Context.Support.ContextHandler, Spring.Core"/>
</sectionGroup>
</configSections>
<spring>
<context>
<resource uri="file://objects.xml"/>
</context>
</spring>
</configuration>
Spring.Context.IApplicationContext context= Spring.Context.Support.ContextRegistry.GetContext();Person person = context.GetObject("Person") as Person;Console.WriteLine(person);
四、将所有的配置信息都保存在应用程序配置文件中
<configuration>
<configSections>
<sectionGroup name="spring">
<section name="context" type="Spring.Context.Support.ContextHandler, Spring.Core"/>
<section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core" />
</sectionGroup>
</configSections>
<spring>
<context>
<resource uri="config://spring/objects"/>
</context>
<objects>
<object id="Person" type="Student"></object>
<object id="Alice" type="Person"></object>
</objects>
</spring>
</configuration>
五、混合使用外部配置文件和嵌入的配置
<configuration>
<configSections>
<sectionGroup name="spring">
<section name="context" type="Spring.Context.Support.ContextHandler, Spring.Core"/>
<section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core" />
</sectionGroup>
</configSections>
<spring>
<context>
<resource uri="file://objects.xml"/>
<resource uri="config://spring/objects"/>
</context>
<objects>
<object id="Alice" type="Person"></object>
</objects>
</spring>
</configuration>
配置 Spring.NET相关推荐
- 如何用Java类配置Spring MVC(不通过web.xml和XML方式)
DispatcherServlet是Spring MVC的核心,按照传统方式, 需要把它配置到web.xml中. 我个人比较不喜欢XML配置方式, XML看起来太累, 冗长繁琐. 还好借助于Servl ...
- myeclipse中配置spring xml自己主动提示
版权声明: https://blog.csdn.net/zdp072/article/details/24582173 这是一篇分享技巧的文章:myeclipse中配置spring xml自己主动提示 ...
- 配置spring整合jpa自动生成数据表
配置spring整合jpa自动生成数据表 applicationContext.xml <?xml version="1.0" encoding="UTF-8&qu ...
- web.xml 通过contextConfigLocation配置spring 的方式
部署到tomcat后,src目录下的配置文件会和class文件一样,自动copy到应用的 classes目录下 spring的 配置文件在启动时,加载的是web-info目录下的application ...
- 丢掉xml使用JavaConfig配置Spring
Spring JavaConfig 最近撸了一遍Spring action 4,发现里面讲的都不再使用xml文件来配置spring,全都采用Java代码来配置. 用Java代码配置的话,感觉要比xml ...
- spring boot框架学习学前掌握之重要注解(2)-通过java的配置方式进行配置spring
本节主要内容: 1:通过代码演示实现零XML配置spring 2:使用重点注解理解 声明: 本文是<凯哥陪你学系列-框架学习之spring boot框架学习>中spring boot框架学 ...
- spring boot注释_使用Spring Boot和注释支持配置Spring JMS应用程序
spring boot注释 1.简介 在以前的文章中,我们学习了如何使用Spring JMS配置项目. 如果查看有关使用Spring JMS进行消息传递的文章介绍 ,您会注意到它是使用XML配置的. ...
- 使用Spring Boot和注释支持配置Spring JMS应用程序
1.简介 在以前的文章中,我们学习了如何使用Spring JMS配置项目. 如果查看有关使用Spring JMS进行消息传递的文章介绍 ,您会注意到它是使用XML配置的. 本文将利用Spring 4. ...
- spring java code配置_Spring-09-使用Java的方式配置Spring
9. 使用Java的方式配置Spring 我们现在要完全不使用Spring的xml配置,全权使用Java来配置Spring! JavaConfig是Spring的一个子项目,在Spring4之后,他成 ...
最新文章
- [BZOJ4766]文艺计算姬
- SpringBoot日志收集-Aop方式-存进数据库一起来和我看看咋收集日志吧!!
- 【转】未能加载文件或程序集或它的某一个依赖项,系统找不到指定的文件
- 如何成为个好Java程序员
- Teams App如何选择用户
- 计算机建筑材料考试试题,建筑材料试题(建筑材料期中试题及)
- 你想进BAT吗?告诉你一个秘密,面试成功率能提高到99%!
- [No00005A]word多文档合一
- 好的网站收藏---长期更新---长期更新---长期更新---长期更新--
- Redis 彻底禁用RDB持久化
- 【译】2021年国外十大AI自动写作软件评测
- 服务器内存条和普通内存条性能,科技知识:服务器内存条和普通内存条区别
- 华为手机序列号前三位_华为Nova2s手机序列号前六位是TPG4C1是什么意思
- STM32F103C8T6有128K的Flash
- Java 7的新特性:文件监视器
- 基因功能分析——哈佛大学
- 基于Django框架的视频播放器设计
- php 心跳包检测,redis的对端心跳检测
- 京东cookie京东ck
- Omnipeek空口抓包(2):扫描无线网络
热门文章
- Kubernetes Deployment与Replica Set
- 程序员的魔法——用Masking GAN让100,000人都露出灿烂笑容
- 《思科UCS服务器统一计算》一导读
- Android WebView 与 JS 交互
- delphi string.split 按照任意字符串分割语句
- Exchange 2010 运维技巧一
- linux安装vsftp教程,CentOS7 vsftp 安装与配置(视频教程)
- SharpDevelop插件系统创建过程全面分析
- 前端一HTML:八:css中与文本相关的属性
- c:数据结构-线性表