내 원래의 대답은 받아 들여졌다, 그러나 지금은 더 좋은 대답이 될 것이라고 믿습니다
귀하의 표현이 정확하지 않습니다, 그것은해야한다 :
<object name="obj1" type="MyTestClass" depends-on="Paths">
<property name="cfg" expression="@(Paths)['cfgFile']"/>
</object>
@(object-id-here)
expression syntax to retrieve an object from the Spring context using an expression을 사용할 수 있습니다.
편집 - 아래 당신이 당신의 app.config
에서 사용할 수있게 구성의이 종류를 좋아하는 것을 상상할 수
를 받아 들여졌다 답변입니다. 그렇다면 PropertyPlaceholderConfigurer
을 사용할 수 있습니다. section 5.9.2.1의 예를 참조하십시오. 귀하의 경우에는
, 그것은 다음과 같이 보일 것입니다 :
<!-- app.config -->
<configuration>
<configSections>
<sectionGroup name="spring">
<section name="context" type="Spring.Context.Support.ContextHandler, Spring.Core"/>
</sectionGroup>
<section name="PathConfiguration" type="System.Configuration.NameValueSectionHandler"/>
</configSections>
<PathConfiguration>
<add key="cfgFile" value="config.txt"/>
<add key="otherCfgFile" value="otherconfig.txt"/>
</PathConfiguration>
<spring>
<context>
<resource uri="mycongfig.xml"/>
</context>
</spring>
</configuration>
그리고 당신의 myconfig.xml
다음이 포함 대신 app.config
, 당신은 다른 IResource
을 사용할 수 있습니다
<!-- ... -->
<object name="obj1" type="MyTestClass">
<property name="cfg" value="${cfgFile}"/>
</object>
<object name="appConfigPropertyHolder"
type="Spring.Objects.Factory.Config.PropertyPlaceholderConfigurer, Spring.Core">
<property name="configSections">
<value>PathConfiguration</value>
</property>
</object>
<!-- ... -->
참고.
대체 솔루션은 구성에 객체로 cfgFile
을 정의한 다음 사전에서 value-ref
을 사용하여이 객체를 참조하는 것입니다 (자세한 방법은 스프링 문서 5.3.2.4 참조). 그러나 이것은 원시 값을 주입하기 때문에 (아마도) ConfigurationObject
을 만들려고 노력하지 않아도되므로 찾고있는 것과 다를 수 있습니다.
오류 메시지를 게시 할 수 있습니까? – Marijn