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 7044499
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:25:01+00:00 2026-05-28T02:25:01+00:00

I am using Spring 3.0.2. I have two relatively simple bean definitions. One has

  • 0

I am using Spring 3.0.2. I have two relatively simple bean definitions. One has a @PostConstruct (bean ‘A’) which triggers a chain of events that the @DependsOn bean (bean ‘B’) needs to be prepared for. However, it seems even though that I stated that the bean ‘A’ is dependent on bean ‘B’, the events (the lifecycle methods) of bean ‘A’ are running before bean ‘B’ is fully initialized.

Does stating that a bean is “dependent” via @DependsOn (or for that matter, depends-on in a bean definition) mean that the dependent bean’s lifecycle methods will be completed before the bean that is dependent on said bean?

Will bean ‘B’ lifecycle methods be completed before bean ‘A’?

UPDATE

Bean A is a custom class that is using a JMS Template to send a message announcing that he has initialized.

The recipient of said message processes it and forwards it’s configuration to a MessageListeningContainer (Bean B).

The first part is happening all before Bean B has been started by the DefaultLifecycleProcessor.

@Component
@DependsOn("beanB")
public class BeanA {
    @PostConstruct
    public void init() {
        // do stuff
    }
}

<bean id="beanB" class="org.springframework.jms.listener.DefaultMessageListenerContainr">
    <!-- other configuration -->
</bean>

I added in my init method the injection of bean b plus two logging statements:

container.isRunning();
container.isActive();

I looked at the spring source and isActive is set to true after the Initialization method (doInitialized is completed). The isRunning is set after the doStart is completed. The doStart is triggered by the DefaultLifecycleProcessor which is occurring after the @PostConstruct annotated methods are called.

How can I guarantee that my Postconstruct method is called AFTER bean b has been initialized AND started?

  • 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-05-28T02:25:02+00:00Added an answer on May 28, 2026 at 2:25 am

    In your particular case @PostConstruct method of bean A won’t be called until B is fully initialized, ie. all its dependencies are injected and its @PostConstruct finishes executing.

    updated:
    Since you are relying on Spring Lifecycle functionality here, can you implement Lifecycle in A and move your JMS call to start() method there?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using .NET 3.5. I have two string arrays, which may share one or
I'm using NHibernate 2.1.2 and Spring 1.3 I have two Text columns (blobs) in
I have been using spring for a while as my IOC. It has also
I have an extremely simple web application running in Tomcat using Spring 3.0.2, Hibernate
Using Spring 3 I have two forms: adding Item and invalidating Item I have
I am using spring + hibernate in my project; I have two classes Reminder
I have two Hibernate entities named Alpha and Beta, and Alpha has a *-to-one
I have two string lists that I'm working with. One that has a list
i am using PrettyFaces 3.3.0 with Spring Security 3 i have two beans UserBean
I am preparing a registration page using JSF/Spring webflow&mvc application. I have added two

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.