码迷,mamicode.com
首页 > 编程语言 > 详细

如何配置Spring的XML文件及使用

时间:2014-07-16 23:23:15      阅读:241      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   使用   文件   

App.config

 1 <?xml version="1.0" encoding="utf-8" ?>
 2 <configuration>
 3     <configSections>
 4         <sectionGroup name="spring">
 5             <section name="context" type="Spring.Context.Support.ContextHandler, Spring.Core"/>
 6             <section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core"/>
 7         </sectionGroup>
 8     </configSections>
 9     <spring>
10         <context>
11             <!--<resource uri="config://spring/objects" />-->
12             <resource uri="file://Spring_bean.xml" />
13         </context>
14         <!--<objects xmlns="http://www.springframework.net" >
15       <object id="UserDao" type="SpringSample.UserDao, SpringSample"/>
16       <object id="UserService" type="SpringSample.UserService, SpringSample" >
17         <property name="UserDao" ref="UserDao"/>
18       </object>
19     </objects>-->
20     </spring>
21 </configuration>

Spring_bean.xml

1 <?xml version="1.0" encoding="utf-8" ?>
2 <objects xmlns="http://www.springframework.net" >
3     <object id="UserDao" type="SpringSample.UserDao, SpringSample"/>
4     <object id="UserService" type="SpringSample.UserService, SpringSample" >
5         <property name="UserDao" ref="UserDao"/>
6     </object>
7 </objects>

Program

1             IApplicationContext ctx = ContextRegistry.GetContext();
2             IUserService userService = ctx.GetObject("UserService") as IUserService;
3             Console.WriteLine(userService.GetName());

 

 

如何配置Spring的XML文件及使用,布布扣,bubuko.com

如何配置Spring的XML文件及使用

标签:style   blog   http   color   使用   文件   

原文地址:http://www.cnblogs.com/mybky/p/3811237.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!