ClassCastException: com.sun.proxy.$Proxy11 cannot be cast to javax.inject.Provider
Author: KrzysztofZCreated Nov 28, 2019Updated May 21, 2026
Hello there,
We created a binding using toProvider()
bind(ProvidedClass.class).annotatedWith(Names.named("providedClass")).toProvider(ClassProvider.class).in(Singleton.class);
While creating Injector the following error happens:
java.lang.ClassCastException: com.sun.proxy.$Proxy11 cannot be cast to javax.inject.Provider at com.google.inject.internal.BoundProviderFactory.get(BoundProviderFactory.java:60)
What is wrong with it?
I also tried to get class instance through:
ProvidedClass providedClass = injector.getInstance(Key.get(ProvidedClass.class, Names.named("providedClass")));
but getting the same exception.
I will appreciate any suggestion.
Thanks Krys
Source: google/guice