14 Replies Latest reply on Feb 15, 2011 12:09 AM by nickynarak

    @PostConstruct annotation not called jboss5.1

      Hey guys,

           I've been stuck with this problem for 2 day's now and i'm running out of ideas, so hopefully someone can help. I've been trying really hard to persuade the head of java to start the next project(starting next week) using richfaces over GWT and need to iron out all the problem's in order to have a solid argument, so please if anyone has ideas/tips i would really appreciate it.

       

      Basically the @PostConstruct method wont fire on my jsf managed bean when using the built in jsf1.2 libraries in jboss 5.1GA using richfaces 3.3.3, i'm using the ee5 web.xml deployment descriptor, below is the header.

       

      web.xml

      <?xml version="1.0" encoding="UTF-8"?>
      <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xmlns="http://java.sun.com/xml/ns/javaee"
          xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
          xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
          version="2.5">

       

      When disabling the built in libraries, packaging libs in the webapp and setting org.jboss.jbossfaces.WAR_BUNDLES_JSF_IMPL to true, @postConstruct works but i get the following error in the jboss log and certain injections like 'FacesConfig.getInstance()' dont work. When deploying jars with the webapp(WEB-INF/lib) i also get 'Class 'za.co.ucs.jsf.basic.ExceptionHandlingActionListener' is not an instance of 'interface javax.faces.event.ActionListener'' even thought the class both extends 'ActionListenerImpl' and implements ActionListener.

       

      I even tried copying the libs from jbossweb.sar into the webapp and again @PostConstruct does not work.

       

      "2010-04-12 16:28:28,805 SEVERE [javax.enterprise.resource.webcontainer.jsf.application] (main) JSF1029: The specified InjectionProvider implementation 'org.jboss.web.jsf.integration.injection.JBossDelegatingInjectionProvider' does not implement the InjectionProvider interface."

       

      The postconstruct annotation in the baking bean is simple.

      public SystemUsersBB() {
            log.info("SystemUsersBB()");
         }

       

         @PostConstruct
         public void init() {
            log.info("init()");
            listUsers();
         }

       

      So there it is, i would appreciate any help or tips as i'm running out of time.

       

      Thanx

      Regards

        • 1. Re: @PostConstruct annotation not called jboss5.1
          ssilvert

          Hi Marko,

           

          Why are you using WAR_BUNDLES_JSF_IMPL?  In AS5.1, this is only used for bundling MyFaces.  If you are using MyFaces then you'll need to check with the MyFaces docs to see how it handles @PostConstruct.

           

          Regards,

           

          Stan

          • 2. Re: @PostConstruct annotation not called jboss5.1

            Hey Stan,

                 I only tried bundling the mojara (ref impl not myfaces) jars with the webapp to see if it would resolve the issue and it did resove the @postconstruct problem but caused even more issues (see previous post) and i started getting even more problems, so the only libraries i have bundled with the webapp are the richfaces3.3.3 jars and i disabled the WAR_BUNDLES_JSF_IMPL option.

             

            What's interesting is that when bundling mojarra in the webapp(just copying the jar's from jbossweb.sar/jsf-libs into WEB_INF/lib) the following shows in the log 'JSF1048: PostConstruct/PreDestroy annotations present.  ManagedBeans methods marked with these annotations will have said annotations processed.' and @PostConstruct work's but i also get the following error 'SEVERE [javax.enterprise.resource.webcontainer.jsf.application] (main)  JSF1029: The specified InjectionProvider implementation  'org.jboss.web.jsf.integration.injection.JBossDelegatingInjectionProvider'  does not implement the InjectionProvider interface.;' and other things break. When not bundling jars neither of the 2 messages show and postconstruct does not work.

             

            The webapp is bundled in an ear as i had to integrate jsf with our existing system and ejb's, i don' know if that helps.

             

            It's too late now and the decision was made last night not to go with jsf but i would still like to get to the bottom of this problem and have everything ready and integrated for our next project, so if anyone has any bright ideas i would appreciate it

             

            Regards

            Marko

            • 3. Re: @PostConstruct annotation not called jboss5.1
              ssilvert

              I'm attaching a simple WAR that I wrote for the JBoss AS test suite.  One of the things it does is to test @PostConstruct.  I just re-verified that it runs correclty on AS 5.1.  Maybe looking at this will help.

               

              Stan

              • 4. Re: @PostConstruct annotation not called jboss5.1
                ssilvert

                You might notice something strange in my faces-config.xml.  It is using the JSF 2.0 deployment descriptor.  But /index.jsf was written for JSF 1.2 and it still works on JBoss AS 5.1.  Of course, you should be using the JSF 1.2 descriptor in your app.

                 

                Stan

                • 5. Re: @PostConstruct annotation not called jboss5.1

                  Hey Stan,    

                       You are putting in a lot of effort in assisting me m8 and i really appreciate it, too bad you are probably in a different country and i can't get you at least a beer

                   

                  The one difference i see in your web.xml

                  your is:

                  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/j2ee/web-app_2_5.xsd

                   

                  and mine is:

                  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee  http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd

                   

                  I don't know if this could be the cause but i will be trying it out soon, also i'm not using jsf 2, i'm using the built in jsf-libs.

                   

                  And yes my faces config is 'xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd'. Could you try and add richfaces 3.3.3 and facesconfig into the mix and see if postconstruct still works, but let me try and change the deployment descriptor first and see if that helps.

                   

                  It's just really strange that when i copy all 3 libraries from jbossweb.sar/jsf-libs into WEB-INF/lib and set org.jboss.jbossfaces.WAR_BUNDLES_JSF_IMPL postconstruct works just fine, but as per previous post other things break.

                   

                  I also just realized richfaces 3.3.3 final has been released and i'm still using 3.3.3CR1, so i'm busy downloading those right now so i can see if that helps. i'm also gonna try and move the facelets jar into 'jbossweb.sar/jsf-libs' from webapp/lib and see if that makes a difference.

                   

                  Once again many thanx for your effort and assistance.

                   

                  Best Regards

                  Marko

                  • 6. Re: @PostConstruct annotation not called jboss5.1
                    ssilvert

                    Let me know what you find.  I can't imagine that RichFaces would affect the functionality of @PostConstruct.

                     

                    Putting the facelets jar in /jsf-libs is not recommended in AS5.

                     

                    Stan

                    • 7. Re: @PostConstruct annotation not called jboss5.1

                      Try using

                       

                      <context-param>
                        <param-name>com.sun.faces.injectionProvider</param-name>
                        <param-value>org.jboss.web.jsf.integration.injection.JBossInjectionProvider</param-value>
                      </context-param>

                      • 8. Re: @PostConstruct annotation not called jboss5.1

                        Hey,

                             Changing the deployment descriptor didn't seem to help and postconstruct was still not called. Ganeshe's solution of adding the injectionProvider param to web.xml did though.  This is strange as web.xml in deployers/jbossweb.deployer/web.xml already has this param set to 'org.jboss.web.jsf.integration.injection.JBossDelegatingInjectionProvider' and it's definitely called because when removing it and using  'FacesContext.getCurrentInstance()' a null pointer is thrown (FacesContext not injected).

                         

                        So many thanx for your assistance guy's, i really appreciate it and hope i can return the favour some day

                         

                        If there is anythink you can think of and would like me to try out to figure out why 'JBossDelegatingInjectionProvider' was not recognising the postconstruct annotation please let me know and i will.

                         

                        Thanx again!

                         

                        Best Regards

                        Marko

                        • 9. Re: @PostConstruct annotation not called jboss5.1
                          ssilvert

                          By any chance did you change the classloading from the default?  Do you have a jboss-web.xml?

                           

                          If that's the case then I think you've found a bug.

                           

                          Stan

                          • 10. Re: @PostConstruct annotation not called jboss5.1

                            Hey Stan,

                                 No we made no classloading changes that i am aware of, if there is any specific setting you can think of i can have a look and let you know what it's set to.

                             

                            and we do have a jboss-web.xml but no classloader has been specified, i also tries changing the descriptor to jee5 format while debugging and it made no difference. Here is the jboss-web.xml

                             

                            "<?xml version='1.0' encoding='UTF-8'?>
                            <!DOCTYPE jboss-web
                                PUBLIC "-//JBoss//DTD Web Application 2.3//EN"
                                "http://www.jboss.org/j2ee/dtd/jboss-web_3_0.dtd">
                            <jboss-web>
                              <security-domain>java:/jaas/ucs-login</security-domain>
                              <context-root>mtm</context-root>
                            </jboss-web>"

                             

                            When bundling the jsf libs with the webapp i got an error "The specified InjectionProvider implementation  'org.jboss.web.jsf.integration.injection.JBossDelegatingInjectionProvider'  does not implement the InjectionProvider interface" and postconstruct did work so the problem is somehow related to JBossDelegatingInjectionProvider, i just dont get why your test app didnt have the same problem and why there aren't many more users with this issue if it is a bug.

                             

                            cheers

                            • 11. Re: @PostConstruct annotation not called jboss5.1
                              ssilvert

                              Yes, I was thinking along the same lines.  That's why I thought you might be doing something with classloading, which is not the norm for most users.

                               

                              Can you remove the jboss-web.xml and see what happens?  I don't think it will make any difference but it's worth a try.

                               

                              Did you try my WAR on your system?  Also, do you have a simple WAR that reproduces this problem?  One that does not have jsf-libs jars in it?

                               

                              Stan

                              • 12. Re: @PostConstruct annotation not called jboss5.1
                                asangawick

                                I had the same issue and couldn't get it done with changing the "injection provider". I have put the "commons-annotations.jar" in my web app lib and it causes this issue.

                                When this jar is removed without any changes to the web.xml @PostConstruct was called.

                                 

                                 

                                Asanga

                                p.s. Hope this might save someone's day

                                • 13. Re: @PostConstruct annotation not called jboss5.1
                                  robbert1

                                  It just saved my day on JBoss AS 6.00 Final, thanks Asanga.

                                   

                                  Regards

                                  Robbert

                                  • 14. Re: @PostConstruct annotation not called jboss5.1
                                    nickynarak

                                    Let's you copy jboss-faces.jar to web\lib folder of project you, because It require some class in this jar.