简体   繁体   中英

dynamic constructor injection in spring

I am learning Spring Core. I am facing some problem.

As in constructor injection, values are passed through xml file which contains bean definition.

I want to define the bean in xml file and want to initialized the bean with dynamic value passed by the user. Is it possible to create bean with dynamic value by using constructor injection ? What are the various ways to do this?

You can't.

You would have to refactor and inject a provider/factory of your required class, ie add a level of abstraction. You can then call this provider/factory with your required values and get an appropriate instance.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM