Question

I'm facing weird behavior with JBoss AS 7 and my application which uses EJB3.1. I successfully lookup bean but when Im trying to cast it to its interface, exception is thrown.

Code in short:

@Local
public interface BusinessObjectsFactory { ... }

@Stateless
@Local(BusinessObjectsFactory.class)
public class JPABusinessObjectsFactory implements BusinessObjectsFactory { ... }

...
Object obj = ctx.lookup("java:app/moduleName/" +
    "JPABusinessObjectsFactory!pckg.BusinessObjectsFactory");
Class c = obj.getClass();
System.out.println(c.getName()); // pckg.BusinessObjectsFactory$$$view36
System.out.println(c.getInterfaces()[0].getName()); // BusinessObjectsFactory 

BusinessObjectsFactory bof = (BusinessObjectsFactory) obj; //cast exception

Any ideas? Note that interface is needed (which implementation is looked up is read from configuration file and might change)

Was it helpful?

Solution

I switched to another lookup strategy while this is no longer issue for me. I'm not sure if this is still present in newest versions of JBoss/Wildfly AS. That's why I'm closing this question.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top