Using Spring.NET's PropertyPlaceholderConfigurer

I found the documentation on this topic rather confusing, so here is my cheat-sheet:

Choice 1:

If you store the Configuration-Keys in the Web.config:

File Web.config / App.config

  1. <configuration>
  2.  
  3. <configSections>
  4. <section name="MyConfigSection"
  5. type="System.Configuration.NameValueFileSectionHandler, System,Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
  6. </configSection>
  7.  
  8. <MyConfigSection>
  9. <add key="ParameterName" value="ParameterValue"/>
  10. </MyConfigSection>
  11.  
  12. </configuration>

File spring-whatever.xml

  1. <objects ...>
  2.  
  3. <object type="Spring.Objects.Factory.Config.PropertyPlaceholderConfigurer, Spring.Core">
  4. <property name="ConfigSections" value="MyConfigSection"/>
  5. </object>
  6.  
  7. <object id="SomePOJO" type="SomeType">
  8. <property name="Foo" value="${ParameterName}"/>
  9. </object>
  10.  
  11. </objects>

If you use more than one config section in the App.config / Web.config file, you will need to register all the sections in the Spring's PropertyPlaceholderConfigurer object by adding them to its ConfigSection property. The values should be separated by a comma.

Choice 2:

Don't use web.config at all, define everything in in spring's object xml only:

File: spring-whatever.xml

  1. <objects ...>
  2.  
  3. <object id="appPropertyConfigurer"
  4. type="Spring.Objects.Factory.Config.PropertyPlaceholderConfigurer, Spring.Core">
  5. <property name="MyConfigSection">
  6. <name-values>
  7. <add key="Foo" value="ParameterValue"/>
  8. </name-values>
  9. </property>
  10. </object>
  11.  
  12. <object id="SomePOJO" type="SomeType">
  13. <property name="Foo" value="${ParameterName}"/>
  14. </object>
  15.  
  16. </objects>

Comments

Choice 2: 'MyConfigSection'

Choice 2:

'MyConfigSection' node cannot be resolved for the specified context [Spring.Objects.Factory.Config.PropertyPlaceholderConfigurer].

pulsar's picture

huh

That's strage... I'll take a closer look at this issue when I'm back from my vaccations. Perhaps I pasted something wrong or the API has changed over the time.