Announcement Announcement Module
Collapse
No announcement yet.
Prototype bean runtime constructor parameters Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Prototype bean runtime constructor parameters

    Hello Community,
    Spring novice here, I've been using Spring for less than a week, and I'm trying to integrate it into and existing Java Command And Control application. I started looking into using Spring to eliminate our use of the Singleton pattern and to help with DI. Now I'm trying to take it a step further and use prototype beans during run time. In the current software, I instantiate statefull objects (several depending on the system conditions) at run time and initialize them by passing parameters into the constructor. I do this so I don't have to worry about calling setters.

    Current Constructor
    Code:
    public MyRuntimeObj (int a, int b) {
       Dependency dependency = new Dependency ();
    }
    In my runtime code I would like to instantiate MyRuntimeObj through ApplicationContext and have the parameters a, b, and the Dependency object injected. As a Spring newbie, is this typically done? I'm having trouble sorting through the documentation, API, and other examples to see if its even possible. Or will/should I instantiate MyRuntimeObj through AppContext with only the Dependancy object passed to the constructor, and pass in the initial parameters a and b with setters from the client code? Thanks for any suggestions.
    Matt
Working...
X