简体   繁体   中英

Guice vs. Spring regarding external libraries

I have a question related to the case where one wants to inject stuff into instances of external libraries, ie classes that cannot be annotated with injection annotations.

Since Guice relies exclusively on annotations, does this mean I cannot handle this use case with Guice? With Spring, I can just declare the injection in XML and there's no need to modify the class (by adding annotations), so it just works.

Are these observations correct and if so, how do you solve the problem when using Guice?

With Guice you can use provider methods , provider bindings , instance bindings (for singletons) and constructor bindings . They don't require the presence of an @Inject annotation.

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