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

  • Home
  • SEARCH
  • 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 8270683
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T06:39:17+00:00 2026-06-08T06:39:17+00:00

I see that it is possible for both Spring beans and other regular classes

  • 0

I see that it is possible for both Spring beans and other regular classes to access the spring application context.

I’m wondering why would a class ever have to deal with Spring context. My understanding is that, in the main method, you bootstrap your application and everything from that point is wired by Spring.

If that is the case, main method should be the only place where you need ApplicationContext. What are the other genuine cases where you need Spring context to get your work done?

  • 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-08T06:39:18+00:00Added an answer on June 8, 2026 at 6:39 am

    Usually beans don’t need to access ApplicationContext directly.

    However, there are cases when direct access is necessary. For example:

    • To access a bean identified by its name at runtime:

      class MyClass implements ApplicationContextAware {
          ...
          public void execute(String actionName) {
              Action action = applicationContext.getBean(actionName);
              action.execute();
          }
          ...
      }
      
    • To pass custom arguments to constuctor of prototype-scoped bean at runtime:

      Bean bean = applicationContext.getBean("myBean", "foo", "bar");
      

      Note that if Bean‘s constructor doesn’t need custom arguments to be passed at runtime, you can inject ObjectFactory<Bean> instead.

    • To trigger autowiring of third-party objects using AutowireCapableBeanFactory.

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

Sidebar

Related Questions

Would what mentioned in the title be possible? Python module style that is. See
I see that Spring has a @Required annotation to mark member variables in beans
I see on SocketIO's web site that it's possible to use SocketIO for mobile
Is it possible to see which constructor was the generic one? internal class Foo<T>
working both with Java and Visual Basic, I see that I can completely manage
I see that this is the same question as Making cmake print commands before
I see that most of big websites are returning javascript objects instead of pure
I see that many people get this error, but their situations all appear a
I see that we cannot use if not exists in the create virtual table
I see that QButtonGroup s let you throw in an integer when you do

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.