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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:10:46+00:00 2026-05-14T02:10:46+00:00

We have a legacy web application (not Spring based) and are looking for best

  • 0

We have a legacy web application (not Spring based) and are looking for best practices to autowire some newer Spring configured (thread safe) service beans into instance variables in several of the legacy servlets. Rewriting every servlet to Spring MVC is out of scope. For testability, we do not want any Spring specific bean lookup code in the Servlets to look up beans by name or similar.

Note that we are not concerned about web specific bean scopes such as session or request; all services are singleton scope.

Below shows relevant code snippet

MyServlet extends LegacyServletSuperclass
{
   private MyThreadSafeServiceBean wantThisToBeAutowiredBySpring;
   ....

}
  • 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-14T02:10:46+00:00Added an answer on May 14, 2026 at 2:10 am

    You can use @Configurable in combination with a <context:load-time-weaver />, and use @Autowired in your servlets. This allows for classes that are not instantiated by spring to use be handled by spring.

    You may use another approach as well – in the init(..) method of your servlet:

    ApplicationContext ctx = 
        WebApplicationContextUtils.getWebApplicationContext(servletContext);
    if (ctx != null) {
        ctx.getAutowireCapableBeanFactory().autowireBean(this);
    }
    

    This will set all spring dependencies (where @Autowired/@Resource are used). It will work in case the service classes are defined in spring, which I assume is the case.

    From testability point of view – if there isn’t a web application context, nothing will happen, and you can manually set your dependencies.You can also mock the application context, if needed, depending on how you are testing your servlets.

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

Sidebar

Related Questions

I have one legacy web application based on struts2 (primarily using annotation). While debugging
I've been looking into a legacy application with a web-based user interface. Given its
We have a legacy ASP.NET web site (not web application, so I can freely
We have some legacy non-backbone code in our web application. Although we attach views
I downloaded nUnit and TestDriven.net. I have a legacy Web Site application and I
I have the 'luck' of develop and enhance a legacy python web application for
I have a legacy web application that is targeted for IE 6 and is
I have a new MVC3 application with a few legacy Web Form pages. I'm
I have a need to migrate a legacy, desktop based, single user, accounting application
In a legacy MFC CHttpServer based web server, we have a command parsing map

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.