xiaodududu / google-guice

Automatically exported from code.google.com/p/google-guice
Apache License 2.0
0 stars 0 forks source link

Bindings fails silenciously instead of raising exception on certains aop configuration #711

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Description of the issue:

I spent hours to figure out that putting interceptors around class that does 
not have any interface won't have the interceptor intercep nor the Binding 
mechanism indicate an error at least at runtime.

Steps to reproduce:
1. Take the AOP sample http://code.google.com/p/google-guice/wiki/AOP
2. Remove "implements BillingService" to RealBillingService 
3. Adapt the module to inject 
// module code 
        bind(RealBillingService.class).toInstance(new RealBillingService ());
        bindInterceptor(Matchers.any(), Matchers.annotatedWith(NotOnWeekends.class), new WeekendBlocker());

// Launcher code
Injector i = Guice.createInjector(new NotOnWeekendsModule());        
        RealBillingService bs = i.getInstance(RealBillingService.class);        
        bs.chargeOrder("", ""); // <== here no interception, no error

4. Run and see no interception

Here we might at least an error or something runtime indicating no interception 
occurs.

Original issue reported on code.google.com by taharqa on 6 Jun 2012 at 4:56

GoogleCodeExporter commented 9 years ago
Interception does not work because you are creating RealBillingService instance 
yourself (in module). See 
https://code.google.com/p/google-guice/wiki/AOP#Limitations

Original comment by Ash2kk@gmail.com on 7 Jun 2012 at 7:09

GoogleCodeExporter commented 9 years ago
Hi you are right with the following

bind(RealBillingService.class).toConstructor( 
RealBillingService.class.getConstructor(String.class));

it works.

thanks

Original comment by taharqa on 7 Jun 2012 at 9:21