您的位置:首页 > 编程语言 > Java开发

【原】[Spring.Net In Action 教程] 二、Spring.Net简单示例

2010-09-12 17:37 387 查看
这个是<<Spring In Action>>开篇示例。

1.项目总体部署结构

配置文件

<?xml version="1.0" encoding="utf-8" ?>
<objects xmlns="http://www.springframework.net"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.net http://www.springframework.net/xsd/spring-objects.xsd"> 
<object id="xGreetingService" type="Model.GreetingServiceImpl, Model">
<property name="greeting" >
<value>Hello!Spring.NET</value>
</property>
</object>
</objects>


5.单元测试类。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using Model;
using Spring.Core;
using Spring.Context;
using Spring.Context.Support;
using Spring.Objects.Factory;

namespace NunitTest
{
[TestFixture]
class GreetingServiceTest
{
private GreetingService m_service;

[TestFixtureSetUp]
public void init()
{
string[] xmlPath = { "file://Spring/SpringConfiguration.xml"};
IApplicationContext n_context = new XmlApplicationContext(xmlPath);
IObjectFactory n_factory = (IObjectFactory)n_context;

this.m_service = (GreetingService)n_factory.GetObject("xGreetingService");
}

[TestFixtureTearDown]
public void release()
{
this.m_service = null;
}

[Test]
public void test_sayGreeting()
{
this.m_service.sayGreeting();
}
}
}

[/code]

6.运行结果



7.本示例代码

Demo
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: