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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:14:16+00:00 2026-06-15T13:14:16+00:00

One of my projects uses Spring MVC to handle URL mappings and dispatch logic.

  • 0

One of my projects uses Spring MVC to handle URL mappings and dispatch logic. I have now to use a third party library which uses its own HttpServlet as the main entry point for its functionalities, but as it’s an optional drop-in replacement for another library I can’t just put the <servlet> declaration in the web.xml: I’d rather use a Controller and Spring profiles to switch between such implementations without having to edit the web.xml.

Is there anything offered OOTB by Spring to handle such cases? I don’t seem to find it right away.

Thanks in advance!

  • 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-15T13:14:17+00:00Added an answer on June 15, 2026 at 1:14 pm

    Answering my own question here just in case my approach can be useful to others.

    There are two key factors I needed to consider:

    • the proper initialization of the servlet
    • give the servlet full control over the HTTP layer (e.g. setting HTTP headers, etc)

    In my specific case there’s no need for properly handling the servlet destruction, as it’s a no-op.

    I ended up writing a dedicated Controller, to be instantiated only if a specific Spring profile is activated, which takes care of instantiating and initializing the Servlet. Then, all the requests will be directly handled in a void handler method, as follows:

    public class ServletDelegatingController implements ServletConfig {
        private final DelegateServlet delegate = new DelegateServlet();
    
        public void handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception { 
            delegate.service(request, response);
        }
    
    
    
        // properly initializes the servlet
        public void setServletConfig(ServletConfig servletConfig) {
            try {
                delegate.init(servletConfig);
            } catch (ServletException e) {
                throw new IllegalStateException("Failure while initializing the servlet", e);
            }
        }
    }
    

    The delegating-servlet.xml for the DispatcherServlet looks like the following:

    <beans profile="custom">
        <bean id="cmisServiceFactory"
              class="com.foo.ServletDelegatingController"/>
    </beans>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two projects.One project is build in MVC asp.net and the other project
I am working on a project that uses Spring MVC, and one of the
I have a spring project which uses different libraries, packed as multiple jars. One
We have a project that uses HP Quality Center and one of the regular
I have a solution with 3 projects.One of UI (contains web pages) and one
I have the digdog MapKitDragAndDrop in one my projects to achieve drag and drop
I have a Visual Studio C++ solution with 3 projects: one contains all classes
In one of my projects, I have a very active classic ASP site with
I have a Spring project that uses Maven and has several profiles to allow
I've been reading/learning more about Spring lately, and how one would use Spring in

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.