• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

setter-based injection in Spring Framework

 
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi , i am trying to learn setter Injection in Spring Framework . i have a class Person with property email .





I am getting confused here , using setter Injection only results in hard coding of values . Please anyone explain me this .
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

using setter Injection only results in hard coding of values .


Hard coding of values ? Can you explain what you are trying to ask ? Can you think of any theoretically better approach ?
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Christophe for responding .

what i mean to ask is that now the property email only consists of the value "my@email.address" . so any time we call the getter method that will only produce this value now .
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ravi Pavan wrote:Thanks Christophe for responding .

what i mean to ask is that now the property email only consists of the value "my@email.address" . so any time we call the getter method that will only produce this value now .



Yes, that is 100% true. So the question is what setters are this ok to have only one value.

This is mostly for things like injecting a DAO into a Service class.

So if I have a service class, I won't want a property that holds state like say User first name. It is like using a Stateful Session Bean in ejb. I want all my services to be stateless. The only getters and setter that I would have in a Service class is injecting the DAOs that the Service needs, so example code here



And always code to an interface never to an actual implementation class.

in my configuration I would create a bean for the DAO and a bean for the Service class and inject the DAO into the Service bean with the <property> tag.

Hope that makes things clearer. You would never have a Domain object defined as a Bean.

Mark
 
Ranch Hand
Posts: 1936
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm still not sure what your question is, Ravi.
Could you please to give an example what are you trying to achieve?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I hope Mark's answer will help. I still can't figure out what your problem is.
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator



Thanks Mark , this made me more clearer . You read my mind .
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic