Announcement Announcement Module
No announcement yet.
How to inject a "private" dependancy, if not possi Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to inject a "private" dependancy, if not possi

    Hi, how can we inject a private dependency, a private setter ? If it's not possible with Spring, why has this not been implemented ?

    I make an allusion to Hibernate mapping ; this framework make possible - in the practice this is very usefull, and basically very necessary - to map db columns to private properties, private setters. This is not impossible to do with Java, and this is very usefull to map complex types of data : private properties match the table structure, and public properties publishing the wished complex java interface just have to handle data conversion.

    Perhaps this is not pertinent in IOC area ?

    Thank you for your answers.

  • #2
    You can use Constructor based injection to overcome a lack of public setters in your beans. This is fully supported by Spring.



    • #3
      Can't speak for the Spring Team, I can see one good reason for Spring not to support it is so we can stick to the JavaBean spec, i.e., a private member without public getter/setter is not a bean property, and should not be meddled with.

      Hibernate's case is somewhat different. It needs to support persisting any objects instead of just beans. Even then, IIRC, direct mappings to private members are discouraged by C. Baur in HiA.