我在学习Spring.Net的过程中,发现不能从程序集加载XML,而教程附带的源码却可以,教程地址:http://www.cnblogs.com/GoodHelper/archive/2009/10/25/SpringNET_Create.html我的代码:
Program.csnamespace SprintLesson4
{
class Program
{
static void Main(string[] args)
{
CreateByConstructor();
} /// <summary>
/// 构造器创建
/// </summary>
static void CreateByConstructor()
{
string[] xmlFiles = new string[]
{
"assembly://SprintLesson4/SprintLesson4/Objects.xml" //如果是从程序集加载xml文件,会报错
//@"E:\Study\SpringNetIOCStudy\SprintLesson4\Objects.xml" //如果是从绝对路径加载xml文件,执行正确
};
IApplicationContext context = new XmlApplicationContext(xmlFiles); IObjectFactory factory = (IObjectFactory)context;
Console.WriteLine(factory.GetObject("personDao").ToString());
}
}
}
PersonDao代码namespace SprintLesson4
{
public class PersonDao
{
public class Person
{
public override string ToString()
{
return "我是全套类Person";
}
} public override string ToString()
{
return "我是PersonDao";
}
}
}
Objects.xml代码:<?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="personDao" type="SprintLesson4.PersonDao, SprintLesson4"></object>
</objects>
程序集名称和默认命名空间名称都是:SprintLesson4请各位帮我看下,到底是什么地方出错了,谢谢
Program.csnamespace SprintLesson4
{
class Program
{
static void Main(string[] args)
{
CreateByConstructor();
} /// <summary>
/// 构造器创建
/// </summary>
static void CreateByConstructor()
{
string[] xmlFiles = new string[]
{
"assembly://SprintLesson4/SprintLesson4/Objects.xml" //如果是从程序集加载xml文件,会报错
//@"E:\Study\SpringNetIOCStudy\SprintLesson4\Objects.xml" //如果是从绝对路径加载xml文件,执行正确
};
IApplicationContext context = new XmlApplicationContext(xmlFiles); IObjectFactory factory = (IObjectFactory)context;
Console.WriteLine(factory.GetObject("personDao").ToString());
}
}
}
PersonDao代码namespace SprintLesson4
{
public class PersonDao
{
public class Person
{
public override string ToString()
{
return "我是全套类Person";
}
} public override string ToString()
{
return "我是PersonDao";
}
}
}
Objects.xml代码:<?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="personDao" type="SprintLesson4.PersonDao, SprintLesson4"></object>
</objects>
程序集名称和默认命名空间名称都是:SprintLesson4请各位帮我看下,到底是什么地方出错了,谢谢
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货