Google Guice desktop application - how to make it work?

岁酱吖の 提交于 2019-12-01 18:55:23

Create Bootstrap class with main method.

Move your current static main method code to non-static one. For example Application#run.

Create main method in Bootstrap class:

public static void main(String[] args) {
    Injector injector = Guice.createInjector(new GuiceModule())
    Application app = injector.getInstance(Application.class);
    app.run();
}

Run Bootstrap class.

Any object that is created using a Guice injector will inject objects into its properties and methods. So one way will be to create an injector in createNewProject.

Injector injector = Guice.createInjector(new BeanModule(),.....
YourMainClass startClass = injector.getInstance(YourMainClass.class);
startClass.kickOfEveryThing();....

You need to at least ask one root object to the injector. This root object will be injected with objects, which will be injected with objects, etc. The the process needs to bootstrap.

See http://code.google.com/p/google-guice/wiki/GettingStarted

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