In EJB 3.1, how does technically proxy a container and effectively spoof my object without an interface?

In EJB 3.1, I can create a session without a bean. When this is injected into other classes, they get an object that is the same type as my pojo, and yet what they actually get is a stub that the class chain interacts with my pojo. How is this trick done? I could figure out if the stub had the same interface type as my pojo, but how does the container create an object of the same type? Reflection? Bit-weaving? Many thanks!

+3


source to share


1 answer


The container creates a proxy class that is a subclass of your class without an EJB interface, and then it overrides all methods for normal proxying (setting, deleting, and calling the actual bean instance) rather than calling methods on your instance. Since java.lang.reflect.Proxy does not support class extension, containers should take a different approach to create the class, probably using a bytecode library like ASM, BCEL, Javassist, etc.



+4


source







All Articles