Win a copy of Modern JavaScript for the Impatient this week in the Server-Side JavaScript and NodeJS forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

setter-based injection in Spring Framework

 
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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: 17346
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • Quote
  • Report post to moderator



Thanks Mark , this made me more clearer . You read my mind .
 
I love a woman who dresses in stainless steel ... and carries tiny ads:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic