Guice

Can't Get Guice Method Interception to Work

若如初见. 提交于 2019-12-18 06:57:15
问题 I'm trying to print a "Hello, AOP!" message whenever Guice/AOP Alliance intercepts a method marked with a particular (custom) annotation. I have followed the official docs (a PDF that can be found here - AOP method interception stuff on pg. 11 ) and cannot get it to work, only compile. First, my annotation: @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.METHOD}) @BindingAnnotation public @interface Validating { // Do nothing; used by Google Guice to intercept certain methods. } Then

How to use jersey 2.0 guice on grizzly

你说的曾经没有我的故事 提交于 2019-12-18 05:59:14
问题 I want to use Guice + Jersey 2.0 on Grizzly. According to this How to use guice-servlet with Jersey 2.0? discussion there is no direct Guice integration for Jersey2 at present but it can be achieved using HK2 as a bridge. I also checked the sample project in Github https://github.com/piersy/jersey2-guice-example-with-test . This project is implemented using Jetty. But my problem is to implement it in Grizzly. On Jetty it is used like this @Inject public MyApplication(ServiceLocator

Generalize guice's robot-legs example with Multibinding

徘徊边缘 提交于 2019-12-18 04:59:07
问题 I have this use case that is very similar to the robot-legs example of Guice, except I don't know how many "legs" I have. Therefore I can't use the annotations needed for the robot-legs example. I expect to gather all these "legs" in an java.util.Set with Guice's Multibindings extension. Technically, in a PrivateModule I would like to expose an implementation directly as an element of the set that will be provided by the Multibindings extension. I just don't know how to do that. For reference

Testing a Play2 application with SecureSocial using dependency injection

廉价感情. 提交于 2019-12-18 04:24:08
问题 Thanks a lot for any guidance! The SecureSocial plugin works fine when I run it from the browser, but I would like to be able to test the rest of my Play app now. Quick Intro SecureSocial's syntax looks like this: def page = SecuredAction(WithProvider("google")) { ... } or this: def page = UserAwareAction { ... } I've been looking here, which seems to be the only question on Stack Overflow even remotely related to my problem with SecureSocial, but I don't quite fancy rewiring bytecode. There

Origin is not allowed by Access-Control-Allow-Origin - how to enable CORS using a very simple web stack and guice

ε祈祈猫儿з 提交于 2019-12-18 02:44:27
问题 I am not sure if the issue is the technologies involved, or my understanding of the technologies. I have an html5 application written in javascript and html hosted on an apache 2.2 server. I have a java application written in java using jetty, guice, jackson, jersey that hosts a simple REST service. Both applications run on the same box, one on port 80 (pure html5 application hosted on apache), the other on 8080 (pure java application hosted on jetty/guice) I believe the answer is in the

Play Framework: Dependency Inject Action Builder

白昼怎懂夜的黑 提交于 2019-12-17 23:27:34
问题 since Play Framework 2.4 there is the possibility to use dependency injection (with Guice). Before I used objects (for example AuthenticationService ) in my ActionBuilders: object AuthenticatedAction extends ActionBuilder[AuthenticatedRequest] { override def invokeBlock[A](request: Request[A], block: (AuthenticatedRequest[A]) => Future[Result]): Future[Result] = { ... AuthenticationService.authenticate (...) ... } } Now AuthenticationService is not an object anymore, but a class. How can I

How do I test Guice injections?

ぃ、小莉子 提交于 2019-12-17 21:56:32
问题 I gave to Google Guice the responsibility of wiring my objects. But, how can I test if the bindings are working well? For example, suppose we have a class A which has a dependence B . How can I test that B is injected correctly? class A { private B b; public A() {} @Inject public void setB(B b) { this.b = b } } Notice that A hasn't got a getB() method and I want to assert that A.b isn't null . 回答1: For any complex Guice project, you should add tests to make sure that the modules can be used

Guice module with type parameters

邮差的信 提交于 2019-12-17 16:26:25
问题 I spent some time wondering if it is possible to write a guice module which itself is parametrized with type T and uses its type parameter to specify bindings. Like in this (not working) example: interface A<T> {} class AImpl<T> implements A<T>{} interface B<T> {} class BImpl<T> implements B<T> {} class MyModule<T> extends AbstractModule { @Override protected void configure() { bind(new TypeLiteral<A<T>>(){}).to(new TypeLiteral<AImpl<T>>(){}); bind(new TypeLiteral<B<T>>(){}).to(new

Accessing Guice injector in its Module?

試著忘記壹切 提交于 2019-12-17 09:22:35
问题 I am extending Guice's AbstractModule and inside of the extending class I need access to Guice's injector. It that possible, if yes, how? 回答1: This is an unusual request. Modules are more like config files than logic files: The Module is read to create the Injector, and then as soon as the Injector is created the module has done its job. For a simple Module, the Injector literally doesn't exist until the Module is ready to be discarded. In any case, rather than requesting an Injector to get

Is it “bad practice” to pass argument to guice module

谁都会走 提交于 2019-12-14 03:59:53
问题 Checking out Guice and I love it. I currently have problem where guice solved it by injecting all the required dependencies I need. But I wonder if I am using Guice in the wrong way. What I require though is define bindings depending on specific instance. And to achieve this I passed the instance in the module. For instance, consider the following (somewhat similar to my problem): public class CustomerModule extends AbstractModule { private Customer customer; public CustomerModule(Customer