Guice

Configuring Apache Shiro with Google Guice Servlet

空扰寡人 提交于 2019-12-04 10:51:09
问题 I'm starting to use Guice/Shiro instead of Spring/Spring Security. I have looked examples from Shiro site, and all configuration examples are made as INI-file examples. Is it possible to configure Shiro in plain Java, as Guice Servlets are meant to be configured? 回答1: Yes it is possible, but requires some glue code if you want Guice to create your Realms. Bind Realm implementation: bind(Realm.class).to(MyRealm.class).in(Singleton.class); Bind WebSecurityManager: @Provides @Singleton

Guice - Jersey - Servlet binding

大兔子大兔子 提交于 2019-12-04 10:27:02
I recently switched to two phase injection and this has created an error in my servlet binding. I am currently toggling between two error modes and not sure which direction is best to pursue. The first error I encountered was: com.sun.jersey.api.container.ContainerException: The ResourceConfig instance does not contain any root resource classes. My servlet module looked like this: public class MyServletModule extends JerseyServletModule { @Override protected void configureServlets() { bind(MyServlet.class).asEagerSingleton(); serve("/*").with(GuiceContainer.class); } } I was able to remove

Wicket Dependency Injection

岁酱吖の 提交于 2019-12-04 10:24:23
I've got a page with a form in Wicket where the form requires a collaborator to get its job done. The collaborator is injected (for which I'm using Guice) and looks something like: public class RegistrationPage extends WebPage { @Inject public RegistrationPage(RegistrationService service) { this.service = service; add(new RegistrationForm()); } private class RegistrationForm extends Form { public RegistrationForm() { // setup } protected void onSubmit() { service.doSomething(); } } } I don't like the idea that the RegistrationService is injected into the RegistrationPage when it's just the

How to use Guava ServiceManager with Guice Injection

五迷三道 提交于 2019-12-04 09:12:46
As mentioned here , Guava ServiceManager can be obtained by ServiceManager manager = injector.getInstance(ServiceManager.class); To make this work, I added the following in my Guice module: @Provides public Set<Service> services(){ return ImmutableSet.<Service>of(MyService()); } In my main class, ServiceManager manager = injector.getInstance(ServiceManager.class); manager.startAsync().awaitHealthy(); How do I get instances of the started services? p.s. Setting the services to be @Singleton feels like a hack. In my opinion, setting the services to be @Singleton isn't a hack at all. That's

Guice equivalent of Spring's @Autowire list of instances

感情迁移 提交于 2019-12-04 04:22:36
In spring when I do: @Autowire List<MyInterface> myInterfaces; then this list will get populated by all beans which implement MyInterface . I didn't have to create bean of type List<MyInterface> . I'm looking for such behaviour in Google Guice. Sofar I went with: Multibinder<MyInterface> myInterfaceBinder = MultiBinder.newSetBinder(binder(), MyInterface.class); Now if I have a bean which implements MyInterface and I bind it, say via: bind(MyInterfaceImpl.class).asEagerSingleton(); it won't be included in my multibinder. I need to add: myInterfaceBinder.addBinding.to(MyInterfaceImpl.class);

Java Generics Error: inconvertible types from command line compiler

扶醉桌前 提交于 2019-12-04 02:38:57
I have some Guice binding code using generics that compiles and functions fine from Eclipse's compiler, but not from the Java (command-line) compiler. I upgraded to the latest (1.7.0_01) Java SDK but still get the following error. [error] ...\BindCategorySelectorActivity.java:42: error: inconvertible types [error] (Class<? extends ListAdapterDataProvider<Row<? extends DatabaseItem>>>) CategoryDataProvider.class); [error] ^ [error] required: Class<? extends ListAdapterDataProvider<Row<? extends DatabaseItem>>> [error] found: Class<CategoryDataProvider> [error] 1 error [error] {file:/.../compile

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

落花浮王杯 提交于 2019-12-04 02:14:05
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! 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) if you want to release a different way of plumbing your application - although of course you could still get

What is the Spring equivalent to FactoryModuleBuilder, @AssistedInject, and @Assisted in Guice?

你离开我真会死。 提交于 2019-12-04 01:54:37
What is the Spring Framework equivalent to FactoryModuleBuilder , @AssistedInject , and @Assisted in Google Guice ? In other words, what is the recommended approach using Spring to create factory objects whose methods accept arguments that the application (not the container) must provide? The Spring static factory method is not the same as FactoryModuleBuilder . FactoryModuleBuilder builds a Guice module that generates "factories" that implement the Factory Method Pattern . Unlike a Spring static factory method, the methods of these factory objects are instance methods, not static methods. The

Guice proxying to support circular dependency

醉酒当歌 提交于 2019-12-04 01:40:23
I'm getting the following error in my code at launch: Tried proxying com.bar.Foo to support a circular dependency, but it is not an interface. How exactly does this proxying work? If I just throw enough classes behind interfaces, will everything be fine? (I know that circular dependencies are usually a code smell, but I think in this case it's ok.) While the "inject an interface" approach is totally valid, and might even be the better solution in some occasions, in general, you can use a simpler solution: Providers. For every class "A" guice can manage, guice also offers a " Provider<A> ".

using guice injection with actor throws null pointer

本小妞迷上赌 提交于 2019-12-04 01:24:30
问题 I'm getting null pointer exception on the field injection of a server which is started as an akka actor. Schedular part: private ActorRef myActor = Akka.system().actorOf( new Props(Retreiver.class)); @Override public void onStart(Application app) { log.info("Starting schedular.....!"); Akka.system() .scheduler() .schedule(Duration.create(0, TimeUnit.MILLISECONDS), Duration.create(30, TimeUnit.MINUTES), myActor, "tick", Akka.system().dispatcher()); } Retreiver class part: public class