最近刚学srping.net 做了一个例子,运行时总是报如题的错误,请问是怎么回事?using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Spring.Context;
using Spring.Context.Support;
namespace SpringNhiberateStart
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void btnGetObject_Click(object sender, EventArgs e)
{
try
{
//拿到容器上下文
IApplicationContext ctx = ContextRegistry.GetContext();
//通过容器获取 对象实例
var order = (Order)ctx.GetObject("order");
if (order == null)
{
MessageBox.Show("Error");
}
else
{
order.Id = 3;
order.Content = "shit";
order.ShowOrder();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
} }
}
}<?xml version="1.0"?>
<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="assembly://SpringNhiberateStart/SpringNhiberateStart/SpringObjects.xml"/>
</context>
<!--容器下的所有的实例的节点都放在此配置下-->
<objects xmlns="http://www.springframework.net">
<description>An example that demonstrates simple IoC features.</description>
<!--type:第一个是类型的全名 ,类型所在的程序集-->
<object name="order" type="SpringNhiberateStart.Order,SpringNhiberateStart">
</object>
</objects>
</spring>
</configuration>
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Spring.Context;
using Spring.Context.Support;
namespace SpringNhiberateStart
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void btnGetObject_Click(object sender, EventArgs e)
{
try
{
//拿到容器上下文
IApplicationContext ctx = ContextRegistry.GetContext();
//通过容器获取 对象实例
var order = (Order)ctx.GetObject("order");
if (order == null)
{
MessageBox.Show("Error");
}
else
{
order.Id = 3;
order.Content = "shit";
order.ShowOrder();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
} }
}
}<?xml version="1.0"?>
<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="assembly://SpringNhiberateStart/SpringNhiberateStart/SpringObjects.xml"/>
</context>
<!--容器下的所有的实例的节点都放在此配置下-->
<objects xmlns="http://www.springframework.net">
<description>An example that demonstrates simple IoC features.</description>
<!--type:第一个是类型的全名 ,类型所在的程序集-->
<object name="order" type="SpringNhiberateStart.Order,SpringNhiberateStart">
</object>
</objects>
</spring>
</configuration>
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货