Announcement Announcement Module
No announcement yet.
No Null-Value with @Value and PropertyPlaceholderConfigurer possible Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • No Null-Value with @Value and PropertyPlaceholderConfigurer possible


    I have a @Component and want to inject the value of a property with @Value and a PropertyPlaceholderConfigurer. My code and configuration looks like this:

    public class MyComponent {

    private String charsetName;


    Spring Beans Config:
    <bean id="PropertyPlaceholderConfigurer" class="org.springframework.beans.factory.config.Pr opertyPlaceholderConfigurer">

    <property name="properties">
    <prop key="myCharsetName">UTF-8</prop>
    <property name="nullValue" value="null">

    Properties file:
    myCharsetName = null

    In short I want to inject null to the Property 'charsetName' of the Component 'myComponent'. But all I get is an Excpetion:

    Caused by: java.lang.IllegalArgumentException: Argument 'value' must not be null.
    at org.springframework.util.Assert.notNull(Assert.jav a:112)
    at org.springframework.util.PropertyPlaceholderHelper .replacePlaceholders(PropertyPlaceholderHelper.jav a:102)
    at org.springframework.beans.factory.config.PropertyP laceholderConfigurer$PlaceholderResolvingStringVal ueResolver.resolveStringValue(PropertyPlaceholderC
    at BeanFactory.resolveEmbeddedValue(AbstractBeanFacto
    at istableBeanFactory.doResolveDependency(DefaultList
    at istableBeanFactory.resolveDependency(DefaultListab
    at org.springframework.beans.factory.annotation.Autow iredAnnotationBeanPostProcessor$AutowiredFieldElem ent.inject(AutowiredAnnotationBeanPostProcessor.ja va:478)

    The @Value seems to replace the property 'myProperty' with the value null (not the String "null") and than the assertion in the PropertyPlaceholderHelper fails.

    If I use the Spring beans config to define and configure the component, everything works fine.

    So what's wrong with my code?

    Thanks and regards