title: CDI: Using Interceptors across different modules / bean archives
body: <p>My Java EE 6 application consists of a war and an ejb module packaged in ear file. I'm using CDI for DI (i.e. I have a beans.xml file in both modules). I want to use a logging interceptor that is defined in the ejb module in the war module, as well. I've enabled the interceptor in the ejb's beans.xml:</p>
  
  <pre><code>&lt;beans&gt;
      &lt;interceptors&gt;
          &lt;class&gt;com.test.interceptor.LoggingInterceptor&lt;/class&gt;
      &lt;/interceptors&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <p>This is working only for the classes that are annotated with the interceptor in the <strong>ejb module</strong>. Classes in war module are not intercepted (although they're annotated with the interceptor too). I thought the solution would be to enable the interceptor in the war's interceptor, as well (like above). But the application cannot be deployed with the following message:</p>
  
  <p>SEVERE: Exception while loading the app : WELD-001417 Enabled interceptor class class com.test.interceptor.LoggingInterceptor is neither annotated @Interceptor nor registered through a portable extension</p>
  
  <p>My LoggingInterceptor looks like this:</p>
  
  <pre><code>@Log
  @Interceptor
  public class LoggingInterceptor {
      private static final Logger logger =  Logger.getLogger(LoggingInterceptor.class.getName());
  
      static {
          logger.setLevel(Level.ALL);
      }
  
      @AroundInvoke
      public Object logMethod(InvocationContext ctx) throws Exception {
          logger.log(Level.FINE, "ENTRY {0} {1}",
                  new Object[]{ ctx.getTarget().getClass().getName(), ctx.getMethod().getName() });
          long startTime = System.nanoTime();
          try {
              return ctx.proceed();
          } finally {
              long diffTime = System.nanoTime() - startTime;
              logger.log(Level.FINE, "RETURN {0} {1}",
                  new Object[]{ ctx.getTarget().getClass().getName(), ctx.getMethod().getName() });
              logger.log(Level.FINE, "{0} took {1} ms", new Object[]{ ctx.getMethod(),
                      TimeUnit.MILLISECONDS.convert(diffTime, TimeUnit.NANOSECONDS)});
          }
      }
  
  }
  </code></pre>
  
  <p>And the interceptor binding:</p>
  
  <pre><code>@InterceptorBinding
  @Retention(RetentionPolicy.RUNTIME)
  @Target({ElementType.METHOD, ElementType.TYPE})
  public @interface Log {}
  </code></pre>
  
  <p>How can I use the interceptor for both modules?</p>