1

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?

swch
  • 1,432
  • 4
  • 21
  • 37
  • It just extends the class. – BalusC Apr 30 '16 at 11:40
  • According to the [docs](https://docs.oracle.com/javase/7/docs/api/java/lang/reflect/Proxy.html) there are two statements: _A proxy class extends java.lang.reflect.Proxy_ and _A proxy class implements exactly the interfaces specified at its creation_ so it is possible to create proxy without interface? According to [this](http://stackoverflow.com/questions/3291637/alternatives-to-java-lang-reflect-proxy-for-creating-proxies-of-abstract-classes) topic it is only possible with CGLIB for example. – swch Apr 30 '16 at 14:19
  • hk2 also uses javassist as cglib seems as though it is not being actively maintained at this time – jwells131313 Apr 30 '16 at 15:17

1 Answers1

2

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.

John Ament
  • 11,595
  • 1
  • 36
  • 45