0 Replies Latest reply on Jul 31, 2014 5:54 PM by Gunnar Hilling

    How should interceptors be activated across modules?

    Gunnar Hilling Newbie



      I'm just writing unit tests for a small project and they should work in a standards-compliant way (of course).

      For testing purposes I'd need to enable an Interceptor on certain beans, however this should only be done when executing the tests. I don't want to touch the production code part of my (maven) project.

      My current approach:

      • Define Interceptor (can be done anywhere for the scope of this question).
      • Activate Interceptor transparently using an extension.
      • Run the tests.

      However using the latest versions of weld this approach doesn't work since the interceptor has to be activated in the beans.xml of the production code.


      To demonstrate the problem (?) I attached a little demo project running a unit test checking if the interceptor was called on a test method.

      The project can be built and tested with weld 2.1.x or 2.2.x. In the attached version the interceptor-activation in the "main" beans.xml is commented out.

      The results are as follows:

      test resultsinterceptor activated in main beans.xmlinterceptor not activated in main beans.xml
      weld 2.1.xOKOK
      weld 2.2.xOKFail

      So two questions:

      1. Which cdi behavior is correct?
      2. In case the behavior of 2.2.4.Final is correct: How could I transparently activate interceptors (or other stuff) on imported modules?

      Kind regards,




      Hi again,


      I'll answer the question myself, at least partly. @Priority has to enable the interceptor. This is perfectly OK in my case.

      However I was surprised because of the change in behavior. Perhaps this should be mentioned in the change log. Or maybe I just missed it.


      Kind regards,



      PS: Posting this as a reply wasn't possible due to technical problems, sorry. I'll try to correct this later.