• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Managed beans aren't constructed running on JBoss 5.1.0 (works fine with Tomcat 6)

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everybody,

This is my first post here

I'm migrating an application from Tomcat 6.0.0.20 (working fine) to JBoss 5.1.0 and I'm facing the following problem:
The application starts fine without error but firstly I realized that the functions marked with the notation @PostContruction wasn't being called and then I figured out that the managed beans simply weren't being constructed/initialized.

For example, I have the following managed bean


When doSomeThing() is fired, I checked by logs that Welcome isn't created and init() isn't called.

Extract of my faces-config.xml


The application uses JSF 1.2 (libraries supplied by JBoss) and RichFaces 3.3.1.

Any thoughts?
Hope anyone can help me.
Thanks
 
Saloon Keeper
Posts: 27763
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the JavaRanch, Neves!

There's absolutely no reason I can see why you should have this problem, but that's probably because of the things I'm not seeing.

Given your bean definitions and your faces-config snipper, a commandButton with an 'action="#{welcome.doSomething}"' should see the construction of a request-scope object of type Welcome and the firing of the action method.

The only flaw I can see is that you're using inheritance, and there are issues with inheriting annotations, but I don't think that applies in your case, since the annotation is on the inheriting object class.
 
Max Neves
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Tim,

Thanks for your reply

Tim Holloway wrote:
There's absolutely no reason I can see why you should have this problem, but that's probably because of the things I'm not seeing.



Yes, that's a weird situation...
The worst thing is I've no clue about what's happening here.

Here's my web.xml used to deploy the application on Tomcat 6:



We use the below web.xml to test on JBoss 5:


The thing is: no matter what web.xml we use, we get the same problem on managed-beans: neither constructors nor methods flagged with @PostConstruct aren't called.


Given your bean definitions and your faces-config snipper, a commandButton with an 'action="#{welcome.doSomething}"' should see the construction of a request-scope object of type Welcome and the firing of the action method.



We realized this problem with JBoss exactly because whenever we fire a button or hyperlink (having an action=#{welcome.doSomething} like you said), 'doSomething()' manipulates objects that should be initilized on 'init()' and, since it isn't called, we got exceptions. After analizing the logs, we figured out this problem.


The only flaw I can see is that you're using inheritance, and there are issues with inheriting annotations, but I don't think that applies in your case, since the annotation is on the inheriting object class.



I see your point.
We have a managed-bean called 'Login' (the only one session-scoped) which isn't a subclasse of 'BaseBean':



Well, we runned the application on JBoss, we got the following logs:



Running on Tomcat yields:


What I concluded so far
I said in the title that the managed beans weren't constructed when deploying on Jboss. It's wrong (thinking in terms of Java, it would be a very weird situation...).
However, the methods flagged with the annotation @PostConstruct aren't called. We don't have this problem with Tomcat.

I'm considering to use the "straighforward" workaround: call my @PostConstruct flagged methods in the constructor.

My reformulated question
Does anyone have any idea about what's going on with @PostConstruct and JBoss?

Thanks a lot
Max
 
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Perhaps the JBoss container is expecting a different @PostConstruct method signature
For Instance , instead of



I just remember reading this somewhere, did not have to try it but you can give it a try
 
Max Neves
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Kavita, thanks for replying

No, you can give the name you want to the method(s) annotated with @PostConstruct, it doesn't matter.

Anyway, I tried your suggestion and it doesn't work:


When executed on JBoss, the application generates the logs below:



Conclusion: the annotation @PostConstruct doesn't work at all

I googled at lot and I wasn't able to find any issue with Jboss and @PostConstruct

Any help will be welcome - I'm confused!
 
Kavita Tipnis
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Might sound silly, but do you have an import for PostConstruct?
 
Max Neves
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Kavita Tipnis wrote:Might sound silly, but do you have an import for PostConstruct?


Hi, sure I do. If I didn't, the application wouldn't have started.
By the way, I'm using Javax annotations:

Does JBoss require another "kind" of annotation?
I mean, has JBoss its own annotations?
 
Kavita Tipnis
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, but happened to read that issue somewhere
here is something that might be helpful
http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4187631#4187631
 
Kavita Tipnis
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, it looks like this issue is still prevalent in JBoss, they have suggested an alternate import(org.jboss.seam.annotations.intercept.PostConstruct)
on the one of the issues, but not sure if it resolved the problem, and I don't see the point because you are not using seam anyways.
So you might be better off doing it the old way
 
Max Neves
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Kavita Tipnis wrote:Sorry, but happened to read that issue somewhere
here is something that might be helpful
http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4187631#4187631



I read it but I'm not using EJB, so I don't know if the clue applies to my case.

Kavita Tipnis wrote:Ok, it looks like this issue is still prevalent in JBoss, they have suggested an alternate import(org.jboss.seam.annotations.intercept.PostConstruct)
on the one of the issues, but not sure if it resolved the problem, and I don't see the point because you are not using seam anyways.
So you might be better off doing it the old way



I'm not sure neither that using a Seam annotation will solve this problem.
Anyway, even if it does, I'm not using Seam at all and putting Seam in my application "just" to solve that doesn't sound brilliant to me.

I posted this problem on JBoss forum but I got no answer so far.
I'll code a very simple JSF application to run on JBoss to test the @PostConstruct as soon as I can.

Thank you guys.
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've been tackling precisely the same issue; so far I've got nothing too. Please post back if you ever determine your issue.
 
Josh Peters
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My issue is solved! I had the JSR 250 api listed as a dependency in my Maven build, and I was distributing the JARs with the WAR project. Changing the scope of that dependency to provided solved my issue.

I've been chewing on that stupid issue for days!

Hope this helps someone else.
 
Max Neves
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Josh Peters wrote:My issue is solved! I had the JSR 250 api listed as a dependency in my Maven build, and I was distributing the JARs with the WAR project. Changing the scope of that dependency to provided solved my issue.

I've been chewing on that stupid issue for days!

Hope this helps someone else.



Hi Josh,
I didn't get it, how have you managed to fix the problem? Just by kicking the jsr250 JAR?
My problem is: I dont use jsr250 at all, and so I continue having any idea about how to solve this silly situation
 
Josh Peters
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, my problem was that both JBoss and my WAR were trying to provide the JSR 250 API. Since I use Maven to build things, my solution was to exclude that JAR from the final result of my build.

Perhaps JBoss doesn't have those jars available to it (are you running on a minimal config server or something more)?

Good luck.
 
I'd appreciate it if you pronounced my name correctly. Pinhead, with a silent "H". Petite ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic