首页 新闻 会员 周边

配置spring.net时,在配置文件中配置对象,出现未找到元素spring的架构信息

0
悬赏园豆:50 [待解决问题]

配置spring.net时,在配置文件中配置对象,出现未找到元素spring的架构信息

求解!

意无意的主页 意无意 | 初学一级 | 园豆:152
提问于:2014-02-26 00:33
< >
分享
所有回答(1)
0

要在项目中添加spring-objects-1.3.xsd,然后在web.config中配置

<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="assembly://SpringDemo/SpringDemo/Objects.xml"/>
      <!--uri有几种方式,包括~/ojects.xml;file://objects.xml;config://spring/objects-->
    </context>   
  </spring>

 

然后是配置Object

<objects xmlns="http://www.springframework.net">
  <object id="ZhangSan" type="SpringDemo.Person,SpringDemo">  
    <property name="Name" value="张三" /><!--普通属性-->
    <property name="Age" value="30"/>
    <property name="Manufacturer1" ref="Manufacturer"/><!--引用一个对象-->
  <property name="Cars">
    <list element-type="object"><!--List<T>-->
      <value>宝马</value>
      <value>奔驰</value>
     <object id="Manufacturer" type="SpringDemo.Manufacturer,SpringDemo" singleton="false"><!--注入另一个实体,默认为单例-->  
       <constructor-arg index="0" value="一汽集团" /><!--构造函数,第0个参数值-->  
       <constructor-arg name="ShangHai" value="上汽集团"/><!--构造函数,根据参数名赋值.不给定index或name就按顺序给值-->
     </object>
    </list>
  </property>
  <property name="Friends">
    <dictionary key-type="string" value-type="int"><!--dictionary<T,K>-->
      <entry key="陶渊明" value="40"/>
      <entry key="孙武" value="45"/>
      <entry key="曹操" value="55"/>
    </dictionary> 
  </property>
  <property name="Cats">
    <set><!--数组-->
      <value>波斯猫</value>
      <value>金吉拉</value>
      <value>巴厘猫</value>
      <value>伯曼猫</value>
      <value>缅因猫</value>  
    </set>
  </property>
  </object> 
</objects>

 

配置完成记得添加Common.Logging.dll和Spring.Core.dll引用到项目中.有时提示找不到架构信息,不要理它,能运行就可以了.

happydaily | 园豆:301 (菜鸟二级) | 2014-02-26 08:49
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册