As far as I know CDI uses dynamic proxy for non-dependent bean injection. If there is a class that implements some interface there is no problem, example:
@SessionScoped
public class MessageBean implements Message {...}
proxy can be created based on Message interface, but what if the class implements no interface:
@SessionScoped
public class MessageBean {...}
The injection into Servlet still works:
@WebServlet("/example")
public class MessageServlet extends HttpServlet {
@Inject
private MessageBean messageBean;
so the question is how it is handled for example by Weld?
Not every proxy is an instance of java.lang.reflect.Proxy
, Weld has its own proxying framework at this point which can subclass any non-final class. Weld also does not use javassist to do proxying (older versions did, but the 2.x are internal).
If you're curious to see how it happens you can find that here: https://github.com/weld/core/blob/master/impl/src/main/java/org/jboss/weld/bean/proxy/ProxyFactory.java
One note - the whole process relies non-final methods and classes. You'll notice that even the CDI spec makes a reference to non-final.