zoukankan      html  css  js  c++  java
  • Spring.Net学习系列 第一篇HelloWorld

    之所以写这篇文章是因为网上很多例子都是不可以用的,大多纯粹是误人子弟。

    这篇文章纯粹是一个HelloWorld,希望能帮到大家。至于配置里需要注意的地方可参考其他文章,这里仅列出可用的项目代码及下载。

    开发环境:VS2005(打了SP1的补丁)

    步骤一:新建一个控制台项目

    步骤二:引用Spring.Core.dll

    步骤三:新建App.config代码如下:

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
        <configSections>
            <sectionGroup name="spring">
                <section name="context" type="Spring.Context.Support.ContextHandler, Spring.Core"/>            
            </sectionGroup>
        </configSections>
        <spring>
            <context>
                <resource uri="file://spring.xml.config"/>
            </context>
        </spring>
    </configuration>

    步骤四:新建spring.xml.config(这个名字可自定,如需改名,则在App.config的rescource里也需一并修改),代码如下:

    <?xml version="1.0" encoding="utf-8" ?>
    <objects xmlns="http://www.springframework.net">
        <object id="hello" type="SpringNetDemo.Hello">
            <property name="HelloWord" value="Hello!你能看到这个证明你成功了!"/>
        </object>
    </objects>

    步骤五:修改项目原来的Program.cs文件:

    using System;
    using System.Collections.Generic;
    using System.Text;
    using Spring.Context;
    using Spring.Context.Support;
    
    namespace SpringNetDemo
    {
        public class Hello
        {
            private string helloword;
    
            public string HelloWord
            {
                get { return this.helloword; }
                set { this.helloword = value; }
            }
        }
        public class Program
        {
            static void Main(string[] args)
            {
                IApplicationContext context = ContextRegistry.GetContext();
                Hello hello = (Hello)context.GetObject("hello");
                Console.Write(hello.HelloWord);
                Console.Read();
            }
        }
    }

    说明:这里的hello.HelloWord就是Spring.Net通过xml的配置实现注入的。有问题的可以留言。

    点击这里下载所有代码

  • 相关阅读:
    javascript编程解决黑化的牛牛问题
    Eclipse中给jar包导入JavaDoc注释文档的方法
    Android网络连接处理学习笔记
    Android Animation学习笔记
    Android中动画学习
    Android 动画效果 --Animation 动画专题研究 一
    Android动画学习笔记-Android Animation
    Android 动画之RotateAnimation应用详解
    Android 动画之ScaleAnimation应用详解
    Android 动画之AlphaAnimation应用详解
  • 原文地址:https://www.cnblogs.com/caiwujia/p/springnet_demo.html
Copyright © 2011-2022 走看看