Announcement Announcement Module
No announcement yet.
Help!! Message Driven Bean Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Help!! Message Driven Bean

    I am totally desperate here. I want to create a MDB that can access my Spring beans with the getBeanFactory().getBean("beanName") method. I've checked the Spring doc and even bought 2 books - pro spring and wrox spring framework. Call me stupid but i just can't understand how to do it.

    I have extended AbstractJmsMessageDrivenBean and have created the following method:

    protected void onEjbCreate() {
    monthMap = (MonthMap)getBeanFactory().getBean("monthMap");
    Map theMap = monthMap.getMonthMap();

    I have also added this to my ejb-jar.xml MDB definition:


    Although I just copied this out the book and have no idea what it does????

    My MDB no longer consumes messages now I've tried to spring it. The onMessage method does not fire even when there are messages on the queue.

    I'm totally desperate to make this work but I just can't do it.

    What did I do wrong?

    I need a quick response or I'll have to drop Spring.


  • #2
    Where in the classpath is bean.xml? The only thing I can think of is AbstractJmsMessageDrivenBean can't find bean.xml.


    • #3
      This is killing me...

      My env-entry is actually like so:


      The applicationContext.xml is in that place on the classpath.

      No errors are thrown to the console when i deploy the bean.


      onEjbCreate() nor onMessage() will fire.

      It is as if WebLogic will not treat this as a MDB?????

      I really don't know what to do.

      This is the worst day I ever had at work. I promised my boss that spring would help bring our project in more quickly - what a mistake.

      Please help!!!!!


      • #4
        Spring can be quite a paradigm shift for people. I think the way Spring encourages people to develop software makes it more modular, more decoupled, easier to unit test. That is where I see a lot of my savings. Spring is there help you glue your decoupled components together.

        But until you get over the learning curve, I certainly don't see Spring as way a to bring you project in more quickly.

        BTW, for the value of ejb/BeanFactoryPath I use a "/" between package names instead of a ".".

        If onEjbCreate is not firing there might be something wrong with your deployment. I use Weblogic 8.1 with Spring and usually when I have problems they show up in the stdout of my weblogic output. When I don't see anything I add logging in the beginning of my onEjbCreate just to make sure its firing. If onEjbCreate throws an exception because the application context isn't initialized or fails to initialize, then onMessage won't get called because Weblogic destroys the MDB.


        • #5

          Weird ... but now weblogic does throw an exception:

          Caused by: class path resource [] cannot be opened because it does not exist.

          Seems you were right. But how is this so because the file is present on the class path.


          I'm a little happier though - at least I get an exception now.

          How can I fix this?


          • #6
            Try using "/" instead of ".".


            • #7
              Thank you so much.

              / instead of . works.

              I thank you for your help, it is much appreciated.

              The other problem - missing exception information seems to be because weblogic's internal log4j seems to have got in a mess. When I create a different domain it works again.

              I'm back on track.


              • #8

                Now I'm trying to configure hibernate with spring as well. I'm nothing if not ambitious.

                When you said "If onEjbCreate throws an exception because the application context isn't initialized or fails to initialize, then onMessage onMessage won't get called because Weblogic destroys the MDB".

                This is the case, but how do i find out what went wrong? There is not a stack trace in sight. I can't debug why my applicationContext.xml failed. I've checked all the weblogic logs and there is nothing. There is nothing to the console either. It just fails silently.

                I hope you can help me again.


                • #9
                  You might try and create an integration test which tests your application context. This won't be exactly the same as running it in Weblogic because things like your datasource will be specified differently, but it should be close enough.

                  Turn up the Weblogic logging level and see if that works. You should also consider turning up whatever logger that Spring is using (using Commons Logging it detects the appropriate one).

                  BTW, why can't you debug your application context? You should change your MDB so that it starts up with a pool of 0 beans, attach your debugger to Weblogic, set a break point in your onEjbCreate and then send a message.

                  Unfortunately I've never had anything fails silently before. If the application context has an error in it I tend to know it.