zoukankan      html  css  js  c++  java
  • 如何配置Spring的XML文件及使用

    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());
  • 相关阅读:
    Go笔记
    EFCore CodeFirst操作MySQL
    基于NET Core简单操作Kafka
    NETCore2.2/3.0+使用带有权限验证的Swagger
    Net操作RabbitMQ
    Mysql报错问题汇总
    GDSM自动化部署shell脚本
    NET操作Redis
    ViewState原理
    使用jsonp跨域请求
  • 原文地址:https://www.cnblogs.com/mybky/p/3811237.html
Copyright © 2011-2022 走看看