Results 1 to 4 of 4

Thread: How to wire a property with a prefix?

  1. #1
    Join Date
    Aug 2004
    Location
    San Diego
    Posts
    3

    Default 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. #2

    Default

    Try with

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

    This should work.

  3. #3
    Join Date
    Aug 2004
    Location
    San Mateo, CA
    Posts
    1,265

    Default

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

  4. #4
    Join Date
    Aug 2004
    Location
    San Diego
    Posts
    3

    Default

    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.

Similar Threads

  1. Order of Bean definitions matters?
    By cfuser in forum Container
    Replies: 2
    Last Post: Oct 21st, 2005, 10:29 AM
  2. Unit testing with JOTM and JtaTransactionManager
    By lalle in forum Architecture
    Replies: 1
    Last Post: Oct 15th, 2005, 09:05 AM
  3. EHCaching Hibernate
    By dencamel in forum Data
    Replies: 3
    Last Post: Sep 6th, 2005, 09:03 PM
  4. Replies: 4
    Last Post: Aug 17th, 2005, 04:42 AM
  5. Replies: 2
    Last Post: May 13th, 2005, 05:42 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •