You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Lance Java <la...@googlemail.com> on 2013/05/29 17:19:59 UTC

ClassCast Exception while loading Service using its interface

Posting this on the user's list rather than dev which is where this belongs

If you bind a service implementation to an interface, tapestry will create
a proxy for you which is why you can't cast it to a concrete type. The
proxy allows live class reloading and other AOP goodies.

Unfortunately your use case requires a hack. You can either create an uber
interface which extends the two interfaces, or you can do the following:

 public class Hack {
   private SineTraceGenerator sineTraceGenerator;

   public Hack(SineTraceGenerator sineTraceGenerator) {
      this.sineTraceGenerator = sineTraceGenerator;
   }

   public SinePattern getSinePattern() {
      return sineTraceGenerator;
   }

   public TraceGenerator getTraceGenerator() {
      return sineTraceGenerator;
   }
}

AppModule
   public Hack buildHack(@AutoBuild SineTraceGenerator sineTraceGenerator) {
      return new Hack(sineTraceGenerator);
   }

   public SinePattern buildSinePattern(Hack hack) {
      return hack.getSinePattern();
   }

   public TraceGenerator buildTraceGenerator(Hack hack) {
      return hack.getTraceGenerator();
   }