Announcement Announcement Module
Collapse
No announcement yet.
How to wire a property with a prefix? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to wire a property with a prefix?

    I am new to the Spring Framework and have a question for the setter based DI: how to wire a property with a prefix?

    Suppose I have the following property:

    //Our code standard mandates a prefix for member variables.
    private String m_Name;

    // Setter method removes the variable prefix.
    public void setName(String newName) {
    m_Name = newName;
    }

    Both following mappings give no writable property exception.
    <property name=”Name”><value>MyName</value></property>
    <property name=”mName”><value>MyName</value></property>

    What is the best way to handle this? Thanks in advance.

  • #2
    Try with

    <property name=”name”><value>MyName</value></property>

    This should work.

    Comment


    • #3
      Spring follows JavaBean conventions for property names. E.g. the method setName() means the property is "name".

      Comment


      • #4
        Thanks for the replies. Now I know what caused my confusion. Here is a summary for other new users.

        For two properties w/ the setters:
        private String m_Name; //Name
        private String m_FName; //First Name

        public void setName() {}
        public void setFName() {}

        Following property definitions work in Spring:
        <property name=”name”><value>John Doe</value><property>
        <property name=”FName”><value>John</value><property>

        Please note it is necessary to capitalize the first letter in property “FName” but not in property “name”.

        Rod, it would be nice if this can be mentioned in the documentation section 3.3.1.

        Thanks again.

        Comment

        Working...
        X