5 Replies Latest reply on Jun 13, 2011 2:55 PM by lightguard

    cannot inject event

    nev

      Hi, I am new to seam catch and trying to use the seam catch from core Java application with JDK 5. I try to inject the seam catch with @Inject 
      Then I have the following code in my catch block.
      catchEvt.fire(new ExceptionToCatch(e));
      However, catchEvt is always null. I cannot inject it.


      Do I need any configuration xml files like Spring? I made sure I have all the jars. I would greatly appreciate for your help. Thank you in advance for your time and help.

        • 1. Re: cannot inject event
          meetoblivion

          If this is some kind of main program/standard app you need to make sure you're bootstrapping your CDI Container.  Understanding a little more about your environment would help as well.

          • 2. Re: cannot inject event
            nev

            Thank you for your reply. Yes, this is a standalone application. So, if I need to bootstrap the CDI container, what is the overhead? Do you think it is wise to use the seam catch module instead of regular try-catch blocks from standalone app?


            Thanks again!

            • 3. Re: cannot inject event
              meetoblivion

              Overhead of using a CDI container, instead of just running your program? It's probably not a lot.  You're talking about the equivalent of running something like spring in your SE application.  The effort of actually implementing it may be a little more than you're expecting.  Everywhere that you're using new needs to be an injection point in CDI,

              • 4. Re: cannot inject event
                nev

                I really appreciate for your response. Is there any good site that shows how to integrate seam catch to standalone application or with spring? I am having a hard time finding this information. I saw a lot of documents what is seam catch and how it is used, but not any example how to use it from core Java app or spring. I would really appreciate if you can help me out.


                Thanks in advance for your time!

                • 5. Re: cannot inject event
                  lightguard

                  You should be doing something like this:


                  @Inject Event<ExceptionToCatch> catchEvent;
                  ...
                  
                  catchEvent.fire(new ExceptionToCatch(e));



                  If that is not working then either



                  1. CDI is not bootstrapped or

                  2. The bean you are trying to inject into is not a ManagedBean (as defined by the spec). Basically it needs to have a no args ctor, or a ctor annotated with @Inject and it cannot be final.

                  3. You do not have a beans.xml in the correct location of your archive.



                  If CDI is running and your bean is a ManagedBean, and you a beans.xml in the correct location then some very odd is going on with your setup. Pasting the code you're using would be very helpful