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

  • No Null-Value with @Value and PropertyPlaceholderConfigurer possible

    Hello,

    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:

    Class:
    @Component("myComponent")
    public class MyComponent {

    @Value("${myCharsetName}")
    private String charsetName;

    ...
    }


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

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

    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 onfigurer.java:388)
    at org.springframework.beans.factory.support.Abstract BeanFactory.resolveEmbeddedValue(AbstractBeanFacto ry.java:699)
    at org.springframework.beans.factory.support.DefaultL istableBeanFactory.doResolveDependency(DefaultList ableBeanFactory.java:695)
    at org.springframework.beans.factory.support.DefaultL istableBeanFactory.resolveDependency(DefaultListab leBeanFactory.java:685)
    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
    Olli
Working...
X