Guice

Associating FXML and Controller in Guice's Module configuration

那年仲夏 提交于 2020-01-01 10:47:49
问题 In my Guice Module I want to associate FXML files and their controllers, currently it looks like this: public class GuiceModule extends AbstractModule { @Override protected void configure() { // associate controllers and fxml files bind(MainController.class).toInstance((MainController)loadController("/main.fxml")); bind(SubController.class).toInstance((SubController)loadController("/content.fxml")); } protected Object loadController(String url) { InputStream fxmlStream = null; try {

Guice injection in a jenkins plugin?

我的未来我决定 提交于 2020-01-01 10:14:56
问题 I just wrote this wiki page on how to do dependency injection in a plugin: https://wiki.jenkins-ci.org/display/JENKINS/Dependency+Injection I want to use this so that I can provide a move requests to external resource to a service class and pass a mock to my Publisher during unit tests. The problem with the example I gave in the wiki is that I cannot provide a mock easily: @Override public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) { Guice

Why there's no configuration file at all for dependency injection with Google Guice?

删除回忆录丶 提交于 2020-01-01 08:24:12
问题 I am checking out Google Guice as DI framework but I am a bit puzzled: why there's no configuration file at all? I found a partial explanation on this question but it is still not clear how I would be able to set my component roles (or any other thing I need to use a switch) without a config file. Any help appreciated! 回答1: The configuration is in the code instead of config files, which is a valid decision for many scenarios. Yes, it means that you have to rebuild (possibly just the modules)

Dropwizard and Guice: injecting Environment

狂风中的少年 提交于 2020-01-01 05:04:28
问题 I am currently building a Dropwizard + Guice + Jersey-based application where the database access is being handled by JDBI for the time being. What I am trying to achieve is to have your typical enterprise architecture, where Resources access Service classes accessing a DAO class that in turn accesses the database. It would be nice to get all this wired up in a proper DI way, although I guess I can build my object graph in the run() method of the application if all else fails. So, I'm running

Dropwizard and Guice: injecting Environment

大城市里の小女人 提交于 2020-01-01 05:04:13
问题 I am currently building a Dropwizard + Guice + Jersey-based application where the database access is being handled by JDBI for the time being. What I am trying to achieve is to have your typical enterprise architecture, where Resources access Service classes accessing a DAO class that in turn accesses the database. It would be nice to get all this wired up in a proper DI way, although I guess I can build my object graph in the run() method of the application if all else fails. So, I'm running

Guice: Difference between Binder#bindConstant() and Binder#bind() … toInstance

允我心安 提交于 2020-01-01 04:16:26
问题 I would like to ask what's the difference between bindConstant().annotatedWith(Names.named("keepAliveInterval")).to(60); and bind(Integer.TYPE).annotatedWith(Names.named("keepAliveInterval")).toInstance(60); I would like to load all my configuration properties with Names.bindProperties(binder(), prop); in my module and I discovered that it uses the latter one for binding properties. Thanks, regards Marek 回答1: I think reasons to use bindConstant() are: It requires that you use an annotated

Google Guice desktop application - how to make it work?

﹥>﹥吖頭↗ 提交于 2019-12-31 00:58:07
问题 I have used Guice in my web app without problems and I wanted to use it in desktop app. I am certainly missing one thing - some way to tell my app how to bind everything and know what is what. In web app, I had declaration for that in Application class, how should I do it in my desktop app? Here is relevant code that I am using: public class GuiceModule extends AbstractModule { @Override protected void configure() { // Enable per-request-thread PersistenceManager injection. install(new

Guice @Nullable annotation

吃可爱长大的小学妹 提交于 2019-12-31 00:41:09
问题 In my service, I have a protected constructor with @Inject and one of the parameters (provider) @Nullable . Any ideas why I am getting com.google.inject.CreationException: Guice creation errors: 1) No implementation for [[service]] was bound. ? Guice is 3.0pre1, @Nullable is ours. 回答1: @Nullable isn't the same as @Inject(optional=true) ... I think if you want to inject null , you need to bind(Service.class).toProvider(Providers.<Service>of(null)) or to otherwise have some kind of provider

Google Guice on Google Appengine: mapping with working _ah

廉价感情. 提交于 2019-12-30 10:36:31
问题 I have a Google Appengine/Guice/Wicket Application. My problem is that due to the mapping I can't access the /_ah/admin Page anymore. My Servlet Module says: serve( "/*" ).with( WicketServlet.class, getWicketServletParams() ); so far it is more or less expected that accessing /_ah/admin gives a 404. I problem is that I don't find a workaround. I tried different combinations of serveRegex(), but even serveRegex( "/.*" ).with( WicketServlet.class, getWicketServletParams() ); leads to problems,

How to scan classes for annotations?

时光怂恿深爱的人放手 提交于 2019-12-30 01:51:13
问题 I have a plain jane servlets web application, and some of my classes have the following annotations: @Controller @RequestMapping(name = "/blog/") public class TestController { .. } Now when my servlet applications starts up, I would like to get a list of all classes that have the @Controller annotation, and then get the value of the @RequestMapping annotation and insert it in a dictionary. How can I do this? I'm using Guice and Guava also, but not sure if that has any annotation related