Spring.Net 配置文件
2015-06-02 09:25
387 查看
方法一. 直接在程序配置文件中配置
方法二. 引用外部xml文件配置
objs.xml文件
创建对象【引用 Spring.Core.dlll Common.Logging.dll】
IApplicationContext ctx = ContextRegistry.GetContext();
Person person = (Person)ctx.GetObject("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 xmlns="http://www.springframework.net"> <object id="Person" type="PhoneNumberWhere.Person, PhoneNumberWhere"> //类的全名称,程序集名称 <property name="Name" value="MyName"/> //简单属性配置,key-value <property name="SonMan" ref="Son"/> //复杂属性配置,ref </object> <object id="Son" type="PhoneNumberWhere.Son, PhoneNumberWhere"> // </object> </objects> </spring> </configuration>
方法二. 引用外部xml文件配置
<?xml version="1.0" encoding="utf-8" ?> <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"/> <resource uri="file://objs.xml"/> //引用xml文件,并把xml设置为【始终复制】嵌入的资源 </context> <objects xmlns="http://www.springframework.net"> </objects> </spring> </configuration>
objs.xml文件
<?xml version="1.0" encoding="utf-8" ?> <objects xmlns="http://www.springframework.net"> <object id="Person" type="PhoneNumberWhere.Person, PhoneNumberWhere"> <property name="Name" value="MyName"/> <property name="SonMan" ref="Son"/> </object> <object id="Son" type="PhoneNumberWhere.Son, PhoneNumberWhere"> <constructor-arg index="0" value="son.txt"/> </object> </objects>
创建对象【引用 Spring.Core.dlll Common.Logging.dll】
IApplicationContext ctx = ContextRegistry.GetContext();
Person person = (Person)ctx.GetObject("Person");
相关文章推荐
- Spring Roo 实站( 一 )部署安装 & 第一个示例程序
- java实现在线用户统计
- myeclipse自定义java注释
- Eclipse-----快速打开当前工程目录 浏览文件插件 EasyExplorer 和 OpenExplorer
- Spring Roo 实站( 一 )部署安装 & 第一个示例程序
- 疯狂Java学习笔记(67)-----------Timer和TimerTask
- 【struts2】五大核心jar包 和 作用
- 集算器用作Java结构化文件计算类库
- 【Android】eclipse下gradle
- Myeclipse 快捷键大全(绝对全)
- springMVC 文件下载
- Simulated Test of SCJP for JAVA2 PlatFORM (only for training)【修改版】
- Java中Runnable和Thread的区别
- Android Studio+jdk 环境安装
- java使用Thumbnailator操作图片
- Unable to create an instance of the Java Virtual Machine
- 利用IKVM在C#中调Java程序(总结+案例)
- Java下利用Jackson进行JSON解析和序列化
- java的线程安全与不安全
- Java知多少(80)图形界面设计基础