我正在学习 Spring.Net。我做了一个小例子来理解标签自动装配,但它不起作用。在我的课下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Spring.Context;
using Spring.Context.Support;
namespace ConsoleApplication6
{
class Program
{
static void Main(string[] args)
{
IApplicationContext context;
context = new XmlApplicationContext("spring.xml");
Texte texte = null;
texte = (Texte)context.GetObject("texte");
texte.print();
Console.ReadKey();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication6
{
class Texte
{
private String _t;
private Description _desc;
public String T
{
get { return _t; }
set { _t = value; }
}
internal Description Desc
{
get { return _desc; }
set { _desc = value; }
}
public void print()
{
Console.WriteLine("text in object: " + _t);
Console.WriteLine("text description: " + _desc.D);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication6
{
class Description
{
private String _d;
public String D
{
get { return _d; }
set { _d = value; }
}
}
}
这里是我的 xml 文件:
<?xml version="1.0" encoding="utf-8" ?>
<objects xmlns="http://www.springframework.net">
<object id = "texte" type = "ConsoleApplication6.Texte" autowire="byName">
<property name = "_t" value = "I am the Text"/>
</object>
<object id = "_desc" type = "ConsoleApplication6.Description">
<property name = "_d" value = "I am the description"/>
</object>
</objects>
Text 对象已实例化,但似乎我的对象 Description 未实例化。
我阅读了文档并检查了所有可以找到的文档: http: //springindepth.com/book/in-depth-ioc-autowiring.html http://www.berchtel.com/archive/diplomathesis/html/ 05.4-spring_.net.html
我还检查了 stackoverflow 中与 autowire 相关的所有问题,但其中大多数都与 autowire 注释有关(我没有尝试这个注释)。
你们中有人知道问题出在哪里吗?