I’m running with the following problem.
I have a few Managed Beans that are shared between, at this moment, two JSF applications. As I don’t want to copy and paste the code in the two (more in the coming future) I’ve put this shared managed beans inside a JAR library. I’ve followed this blog: http://jsflive.wordpress.com/2011/03/24/custom-component-library/
Well, even if I put the faces-config.xml inside JAR/META-INF/ the @ManagedBean and @ViewScoped didn’t work. I couldn’t realise why, but if I register the beans in faces-config.xml (JAR ones, not WAR ones) this problem goes away.
I could live with this, but for my surprise the @PostConstruct annotation didn’t get called for this managed beans inside JAR library. I don’t get any error, warning or else. I suppose that the beans are getting loaded, but the their annotations aren’t being processed.
Have anyone faced this?
My environment:
Glassfish 3.1.1 (build 12)
JSF 2.1.3
Thanks in advance.
Then the
@PostConstructannotation has not been scanned. This is result of the same problem which caused that your@ManagedBeanannotation and likes have not been scanned.There are several causes of this problem:
You used Mojarra 2.1.0 on Jetty/Tomcat/JBoss AS. This is a very specific bug in the annotation scanner. See issue 1937.
Your
/WEB-INF/faces-config.xmlfile has ametadata-complete="true"attribute. This conflicts the 1st requirement as outlined in JSF 2.0 specification:Your JAR file is not been dropped in
/WEB-INF/lib, but somewhere else in the classpath. This conflicts the 4th requirement as outlined above.Your webapp’s
/WEB-INF/faces-config.xmland/or your JAR’s/META-INF/faces-config.xmlis not JSF 2.x compatible. It must not contain a JSF 1.x specific<faces-config>declaration, but a JSF 2.x specific one.The one in JAR’s
/META-INFis allowed to be completely empty.Cause 1 can be scratched in your particular case as you’re using Mojarra 2.1.3 on Glassfish. I’ll bet it to be the other causes.