1 Reply Latest reply on Jul 24, 2014 9:58 AM by Dawid Stępień

    CDI interceptor binding doesn't work

    Dawid Stępień Newbie



      I'm New to the forum so first of all I want to say hello. I'm learning JEE from few months and like every newbie I encounter issues. In most cases I find the solutions at google, books, forums, stackoverflow etc., but sometimes it doesn't work. So I'm here and I believe that I find few answers from the more experienced developers.


      Recently I created a little project with CDI examples. Everything works fine except features that are configured with deployment descriptor. My simple app works without interceptor bindings or alternatives defined in beans.xml. So my question is do I need to configure something else in the JBoss?


      Below I present my interceptor binding files. You can find all project here: https://github.com/dstepien/jee7-examples



      <beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
             xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
             version="1.1" bean-discovery-mode="all">



      package pl.dawidstepien.jee.examples;
      import java.util.logging.Logger;
      import javax.annotation.PostConstruct;
      import javax.inject.Inject;
      import javax.interceptor.AroundInvoke;
      import javax.interceptor.Interceptor;
      import javax.interceptor.InvocationContext;
      @Interceptor @Profiling
      public class ProfileInterceptor {
        Logger logger;
        public void logMethod(InvocationContext invocationContext) throws Exception {
          logger.info("\n\nWelcome, this is " + invocationContext.getTarget().getClass().getSimpleName() + "\n");
        public Object profile(InvocationContext invocationContext) throws Exception {
          long initTime = System.currentTimeMillis();
          logger.info("ENTER: " + invocationContext.getMethod().getName());
          try {
            return invocationContext.proceed();
          } finally {
            long diffTime = System.currentTimeMillis() - initTime;
            logger.info(invocationContext.getMethod().getName() + " took " + diffTime + " millis");



      package pl.dawidstepien.jee.examples;
      import java.util.logging.Logger;
      import javax.ejb.Remote;
      import javax.ejb.Stateless;
      import javax.inject.Inject;
      public class DatePrinterBean implements DatePrinter {
        Logger logger;
        @Inject @SimpleDate
        DateGenerator dateGenerator;
        public void printDate() {
          logger.info("Today's date: " + dateGenerator.generateDate());



      package pl.dawidstepien.jee.examples;
      import static java.lang.annotation.ElementType.METHOD;
      import static java.lang.annotation.ElementType.TYPE;
      import static java.lang.annotation.RetentionPolicy.RUNTIME;
      import java.lang.annotation.Retention;
      import java.lang.annotation.Target;
      import javax.interceptor.InterceptorBinding;
      @Target({TYPE, METHOD})
      public @interface Profiling { }