This week's book giveaway is in the Programmer Certification forum.
We're giving away four copies of OCP Oracle Certified Professional Java SE 21 Developer Study Guide: Exam 1Z0-830 and have Jeanne Boyarsky & Scott Selikoff on-line!
See this thread for details.
  • 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

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 .
 
Yeah, but does being a ninja come with a dental plan? And what about this tiny ad?
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic