使用spring.net生成对象时,出现一下错误:
Cannot resolve type [CreateObjects.Domain.StudentDao,CreateObjects.Domain] for object with name 'StudentDao' defined in file [E:\.NET Study\Spring.NET学习笔记\Spring.NET Study\SpringNetLesson2\CreateObjectsBySpringDotNet\Objects.xml] line 8
配置文件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="StudentDao" type="CreateObjects.Domain.StudentDao,CreateObjects.Domain"> </object> </objects>
客户端代码如下:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using CreateObjects.Domain; using Spring.Context; using Spring.Context.Support; using Spring.Objects.Factory; namespace CreateObjectsBySpringDotNet { class Program { static void Main(string[] args) { //使用构造器创建对象 Console.WriteLine("使用构造器创建对象:"); string[] xmlFiles = new string[] { "file://../../Objects.xml" }; IApplicationContext iContext=new XmlApplicationContext(xmlFiles); IObjectFactory iObjectFactory = iContext; Console.WriteLine(iContext.GetObject("StudentDao").ToString()); } } }
找了好久都没找到错误的原因,希望大家帮忙看看!谢谢啦