2016-06-27 33 views
0

我在使用spring.net創建對象時遇到問題,並且需要解決方案。如何使用spring.net爲TypeAliases做屬性注入

安裝說明: 我有下面的TypeAliases配置文件。

<objects xmlns="http://www.springframework.net" > 
    <object id="TypeAlias" type="Spring.Objects.Factory.Config.TypeAliasConfigurer, Spring.Core"> 
     <property name="TypeAliases"> 
      <dictionary>     
       <entry key="ABCHost" value-ref="XYZ"/> 
      </dictionary> 
     </property> 
    </object> 
    <object id="XYZ" type="ABC.ABCHost, ABCHost" > 
     <property name="Viewer" ref="ViewerFactory" /> 
    </object> 
</objects> 

爲什麼我做物業注入是因爲ObjectPoolFactory使用默認的構造函數。創建對象時,我希望通過下面的spring文件創建這個Viewer屬性。

<object id="ViewerFactory" type="XYZViewerFactory, XYZViewer" singleton ="true"> 
    </object> 

問題: 當運行應用程序,我接到一個電話到默認ABCHost類和觀衆財產的構造函數獲取值XYZViewer。之後,我得到一個彈簧錯誤 -

ServiceProvider.get_AppContext - ServiceProvider.cs(31) 
    Spring Error : 
Spring.Objects.Factory.ObjectInitializationException: 
------------------------------------ 
--- Message 
------------------------------------ 
Invalid value 'ABCHost' for custom type alias - must be a System.String or System.Type. 

------------------------------------ 
--- Stack Trace 
------------------------------------ 
    at Spring.Objects.Factory.Config.AbstractConfigurer.ResolveRequiredType(Object value, String errorContextSource, String errorContext) 

你能幫助找到解決這個問題的辦法嗎?提前致謝。

回答

0

TypeAlias使用非常簡單的XML配置OUTSIDE彈簧/對象中定義:

<configuration> 

    <configSections> 
    <sectionGroup name="spring"> 
     <!-- other configuration section handler defined here --> 
     <section name="typeAliases" type="Spring.Context.Support.TypeAliasesSectionHandler, Spring.Core"/> 
    </sectionGroup> 
    </configSections> 

    <spring> 
    <typeAliases> 
     <alias name="WebServiceExporter" type="Spring.Web.Services.WebServiceExporter, Spring.Web"/> 
    </typeAliases> 
    </spring> 

</configuration> 

docs看到更多。

TypeAlias在spring/typeAliases結構中定義。