java - Creating beans on-demand using spring -


I want to make some spring beans after the startup in the factory-eye pattern. For example, every time I have to do some work and I need to make a work bean (which is probably dependent on other singleton spring beans) and execute it.

There may be many pieces of work to work on here Also, each work bean requires independent (prototype).

Do any similar patterns people use to achieve it?

As I see, I want to do container / applicationContext in any way but I really do not want to call the applicationContext / beanFactory scatter injection and everywhere BBA ("...") Am

I thought of something like this (note "factory" is something I imagine, something exists instead)

   << xxx: factory bean = "mytask">    

And then the code

  class MyTaskExecutor {Private factory  jobs; Public Zero SetTexFinancial (Factory  Taskfiner) {this.taskFactory = taskFactory;} }  

and perhaps an annotation session

  class MyTaskExecutor {@Factory (MyTask.class) private factory  taskFactory;}  

Maybe something like the above Is it already? Or am I forgetting something fundamental somewhere.

I realized that I can have a singleton mine taskfactory and it can be used to use "new" But then I have to pass the dependents to all the factories who feel misunderstood.

To summarize the question A

R's

Thank you for any input.

I think you are ending the problem. You only have to type a TaskFactory class (nothing special about it, no special interfaces or annotations). Efficient will be injected with all other beans, and there is a createTask method that works on demand, and new work in the context of essential spring beans The client code that is created is injected with the TaskFactory , and when required call createTask .

The Spring does not provide any clear support for whatever it is trying to do. The choice of the factory-method XML attributes and the factorial interface are only useful for the scope of the scope of the scope, and if you want to create them on demand, this means the Field = "prototype" , and this means that getBean () .

Edit: It is probably worth mentioning that prototype-scod beans are not true what is designed for spring. Yes, it supports them, but their use is not a very educated experience. If you want to actually go down this road, then it's worth it. It is very powerful, but the runtime classloader is not always suitable due to obstacles.


Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -