Comment by bells...@gmail.com:
hi below is my code:
BillingModule.java
public class BillingModule extends AbstractModule {
@Override
public void configure() {
bind(Calendar.class).to(GregorianCalendar.class);
bindInterceptor(Matchers.any(),
Matchers.annotatedWith(NotOnWeekends.class), new WeekBlocker(
getProvider(Calendar.class)));
bind(TransactionLog.class).toProvider(TransactionLogProvider.class);
bind(CreditCardProcessor.class).to(PaypalCreditCardProcessor.class);
}
}
Main.java:
public class Main {
/**
* @param args
*/
public static void main(String[] args) {
Injector injector = Guice.createInjector(new BillingModule());
BillingService billingService = injector
.getInstance(RealBillingService.class);
BillingService billingService2 = injector
.getInstance(RealBillingService.class);
System.out.println(billingService + "" + billingService2);
billingService.chargeOrder(new PizzaOrder(), new CreditCard());
}
}
but the result is exception:
<font color="#FF0000">
2013-5-20 14:26:06 com.google.inject.internal.MessageProcessor visit
信息: An exception was caught and reported. Message:
java.lang.IllegalStateException: This Provider cannot be used until the
Injector has been created.
java.lang.IllegalStateException: This Provider cannot be used until the
Injector has been created.
at
com.google.inject.internal.util.$Preconditions.checkState(Preconditions.java:142)
at com.google.inject.spi.ProviderLookup$1.get(ProviderLookup.java:87)
at guide.WeekBlocker.<init>(WeekBlocker.java:29)
at guide.BillingModule.configure(BillingModule.java:34)
at com.google.inject.AbstractModule.configure(AbstractModule.java:59)
at
com.google.inject.spi.Elements$RecordingBinder.install(Elements.java:223)
at com.google.inject.spi.Elements.getElements(Elements.java:101)
at
com.google.inject.internal.InjectorShell$Builder.build(InjectorShell.java:133)
at
com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:103)
at com.google.inject.Guice.createInjector(Guice.java:95)
at com.google.inject.Guice.createInjector(Guice.java:72)
at com.google.inject.Guice.createInjector(Guice.java:62)
at guide.Main.main(Main.java:19)
Exception in thread "main" com.google.inject.CreationException: Guice
creation errors:
1) An exception was caught and reported. Message: This Provider cannot be
used until the Injector has been created.
at
com.google.inject.internal.InjectorShell$Builder.build(InjectorShell.java:133)
1 error
at
com.google.inject.internal.Errors.throwCreationExceptionIfErrorsExist(Errors.java:435)
at
com.google.inject.internal.InternalInjectorCreator.initializeStatically(InternalInjectorCreator.java:154)
at
com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:106)
at com.google.inject.Guice.createInjector(Guice.java:95)
at com.google.inject.Guice.createInjector(Guice.java:72)
at com.google.inject.Guice.createInjector(Guice.java:62)
at guide.Main.main(Main.java:19)
Caused by: java.lang.IllegalStateException: This Provider cannot be used
until the Injector has been created.
at
com.google.inject.internal.util.$Preconditions.checkState(Preconditions.java:142)
at com.google.inject.spi.ProviderLookup$1.get(ProviderLookup.java:87)
at guide.WeekBlocker.<init>(WeekBlocker.java:29)
at guide.BillingModule.configure(BillingModule.java:34)
at com.google.inject.AbstractModule.configure(AbstractModule.java:59)
at
com.google.inject.spi.Elements$RecordingBinder.install(Elements.java:223)
at com.google.inject.spi.Elements.getElements(Elements.java:101)
at
com.google.inject.internal.InjectorShell$Builder.build(InjectorShell.java:133)
at
com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:103)
... 4 more
</font>
For more information:
http://code.google.com/p/google-guice/wiki/AOP
--
You received this message because you are subscribed to the Google Groups
"google-guice-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to google-guice-dev+unsubscr...@googlegroups.com.
To post to this group, send email to google-guice-dev@googlegroups.com.
Visit this group at http://groups.google.com/group/google-guice-dev?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.