Mimicking Spring profiles in Guice

三世轮回 提交于 2019-12-21 03:52:52

问题


In Spring, if I want to have one set of objects for production, and another for local development/testing. I could use the @Profile annotation to designate the different classes, and switch between them by providing a system property when starting the app.

Is there anything like this in Guice, or do I need to manually check some property myself and load a different set of modules when bootstrapping my Injector?


回答1:


You'll need to identify the environment yourself, and choose which modules to apply in which environment, but you do have access to Modules.override to specifically override certain bindings without having to create a lot of module variants. Use it judiciously—it's very easy to get your modules tangled if you override many bindings or in unpredictable places.



来源:https://stackoverflow.com/questions/18112299/mimicking-spring-profiles-in-guice

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!