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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:35:02+00:00 2026-06-13T17:35:02+00:00

In Spring MVC with annotation, we mark any POJO with @Controller. In this controller

  • 0

In Spring MVC with annotation, we mark any POJO with @Controller.
In this controller we can get WebApplicationContext, using autowired property.

@Controller
public class HomePageController {

@Autowired
ApplicationContext act;

    @RequestMapping("/*.html")
    public String handleBasic(){
        SimpleDomain sd = (SimpleDomain)act.getBean("sd1");
        System.out.println(sd.getFirstProp());
        return "hello";
}

But in this approach we do not have servletContext handy with us. So is there way we can still use older way of getting WebApplicationContext ? i.e.

WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext)

How will we get servletContext here ?

I am not facing any compulsion to use old way; so this question is just out of curiosity to check flexibility of spring.
Also It can be a interview question.

  • 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-13T17:35:02+00:00Added an answer on June 13, 2026 at 5:35 pm

    You can just inject it into your controller:

    @Autowired private ServletContext servletContext;
    

    Or take HttpServletRequest as a parameter and get it from there:

    @RequestMapping(...)
    public ModelAndView myMethod(HttpServletRequest request ...){
        ServletContext servletContext = request.getServletContext()
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

earlier I use Spring MVC and annotation @ModelAttribute. @Controller public class ArticleController { @ModelAttribute(articles)
I am using Spring MVC with annotation configuration. I have a controller class for
I'm using spring MVC and spring security. I have annotation-driven controller and trying to
I trying spring 3 mvc this package is org.spring.test and code is @Controller @RequestMapping(/welcome)
This is a spring mvc application using IntelliJ. I'm getting this error: org.springframework.orm.hibernate3.HibernateSystemException: Unknown
I'm using Spring MVC with Jackson. It requires <mvc:annotation-driven /> . It works with
I am using Spring MVC 3 and I try to use the validation annotation
i have written a small webapp using spring-security and spring-mvc with an annotation based
I'm using Spring MVC (3.0) with annotation-driven controllers. I would like to create REST-ful
This is probably the millionth question about this Spring MVC error, but I can't

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.