Announcement Announcement Module
No announcement yet.
Public attribute dependency injection Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Public attribute dependency injection

    Is it possible to use dependency injection from the config file for setting public attributes?

    The class I am trying to create acts like a structure, it has no constructor, and no setter methods, just public attributes, its also marked final so I cannot extend it and create setter methods or constructors.

    Given this class, and the fact I cannot modify it, is there a way to set its attributes from the config file?

  • #2
    You can create a wrapper class for that final class, and then can do the injection..


    • #3
      Extending AbstractFactoryBean is the best way to implement such a wrapper. It implements FactoryBean which is the basis of most of Spring's utility classes (like JndiObjectFactoryBean, ProxyFactoryBean, etc).