Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9075947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T18:59:32+00:00 2026-06-16T18:59:32+00:00

Probably my question is a trivial one, but I never used an application scope

  • 0

Probably my question is a trivial one, but I never used an application scope bean before. I need the application bean because I have to do time consuming transactions on the database.
my search didn’t satisfy my curiosity at all.
I don’t know why but I didn’t manage to initialize the bean (it is null) or it the app crashed.
So I have an application scope bean

@ManagedBean(eager=true)
@ApplicationScoped
public class ApplicationContainer {
...
}

eager=true I read that tells JSF to initiate the bean every time when the application server (I use GlassFish) is started.

I read in several places that I just have to put this annotation and the bean gets initialized.
For me it doesn’t…
After I read that if I want to inject the application bean into another bean I have to use @PostConstuct annotation

@ManagedBean
@SessionScoped
public class TestsBean implements Serializable {

    private static final long serialVersionUID = 1L;
    @ManagedProperty(value = "#{container}")
    private ApplicationContainer container;

    @PostConstruct
    public void init() {
    container.contructContainer();
    }

this gives an error in other bean that I inject the TestsBean into…

  • if the application bean gets initialized when the server starts what method does it call in the body of the application bean to do the actions that it requires? Or in the injected bean it’s done in the post construct method?

Please tell me the proper way to handle application beans. I an really confused…

Thank you all for your time!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T18:59:34+00:00Added an answer on June 16, 2026 at 6:59 pm

    There are 2 potential mistakes.

    First, the @ManagedBean(eager=true) works, as its javadoc says, only on application scoped JSF managed beans. So it works only when you have used @ApplicationScoped of javax.faces.bean package (and thus not javax.enterprise.context package!). The eager=true basically means that the bean will be auto-instantiated on webapp’s startup instead of only later when it’s referenced for the first time in EL.

    Second, the managed bean name defaults to the classname in decapitalized form according the Javabeans specification. You didn’t explicitly specify any managed bean name like @ManagedBean(name="container", eager=true), so the managed bean name will default to applicationContainer, however yet you’re still attempting to reference it as #{container} instead of #{applicationContainer}.

    You are not clear at all on which problems/errors you’re facing. If you’re getting an exception, you should absolutely read/interpret it and if you’re unable to understand it, copypaste it in its entirety -including the stacktrace- in the question. It represents namely the whole answer to your problem at its own. You just have to interpret and understand it (or we just have to explain it in layman’s terms). You should really not ignore them and leave them out the question as if they are irrelevant decoration. They are not!

    All with all, the complete and proper approach would be, complete with the import declarations just to be sure, and also some poor man’s stdout prints for debugging:

    package com.example;
    
    import javax.faces.bean.ApplicationScoped;
    import javax.faces.bean.ManagedBean;
    
    @ManagedBean(eager=true)
    @ApplicationScoped
    public class ApplicationContainer {
    
        public ApplicationContainer() {
            System.out.println("ApplicationContainer constructed");
        }
    
    }
    
    package com.example;
    
    import java.io.Serializable;
    import javax.annotation.PostConstruct;
    import javax.faces.bean.ManagedBean;
    import javax.faces.bean.ManagedProperty;
    import javax.faces.bean.SessionScoped;
    
    @ManagedBean
    @SessionScoped
    public class TestsBean implements Serializable {
    
        @ManagedProperty("#{applicationContainer}")
        private ApplicationContainer container;
    
        public TestsBean() {
            System.out.println("TestsBean constructed");
        }
    
        @PostConstruct
        public void init() {
            System.out.println("ApplicationContainer injected: " + container);
        }
    
        public void setContainer(ApplicationContainer container) {
            this.container = container;
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is probably a very trivial question, but.. Assuming we have a variable 'a'
A beginner's question, probably a trivial one. Here's the XUL code snippet: <window xmlns=http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul>
Probably a trivial question, but in which order does Exception::getTrace return calls? Most recent
This is probably a trivial question for most but here goes... I am using
I know it probably sounds like very trivial question but I couldn't find any
Ok so this is probably a trivial question but I'm having trouble visualizing and
Possible Duplicate: C++ Comma Operator that probably a trivial question, but I don't know
I have what is probably a really dumb grep in R question. Apologies, because
Probably this question was already asked before, but my google-fu and SO-Search did not
This is probably a trivial question, but how do I parallelize the following loop

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.