Results 1 to 2 of 2
  1. #1
    Java Tip's Avatar
    Java Tip is offline Moderator
    Join Date
    Nov 2007
    Posts
    1,694
    Blog Entries
    430
    Rep Power
    10

    Default How to set the property of Bean by constructor injection

    This tip shows the way to set the property of the bean by constructor injection.

    Java Code:
    public class sample{ 
         String name; 
         public sample(String a) 
         { 
            name = a; 
         }    
    }
    The following code is used for setting the property.

    Java Code:
     <bean id="bean1"  class="sample"> 
    <constructor-arg> 
      <value>Sample Bean Value</value> 
       </constructor-arg>   
    </bean>

  2. #2
    rjuyal's Avatar
    rjuyal is offline Senior Member
    Join Date
    Mar 2008
    Location
    Delhi, India
    Posts
    194
    Rep Power
    7

    Default Oops

    But, it is not acceptable.
    spring advised to set the value using setters and not by constructor :)
    i am the future

Similar Threads

  1. Replies: 0
    Last Post: 03-29-2008, 01:38 PM
  2. Replies: 0
    Last Post: 03-29-2008, 01:38 PM
  3. Replies: 0
    Last Post: 10-04-2007, 10:18 PM
  4. Replies: 0
    Last Post: 09-26-2007, 09:29 PM
  5. Replies: 0
    Last Post: 09-26-2007, 09:28 PM

Posting Permissions

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