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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T03:08:07+00:00 2026-06-09T03:08:07+00:00

I want to map spring mvc controller to root ( /** ) path (and

  • 0

I want to map spring mvc controller to root (/**) path (and not sub-folder such as “/something”) while making exceptions with mvc:resources (open to another method).

This should be the ABC of that framework but apparently is a very complicated stuff to ask of it.

My app-servlet.xml has these obvious mapping exceptions:

<mvc:resources mapping="/favicon.ico" location="/favicon.ico" />
<mvc:resources mapping="/robots.txt" location="/robots.txt" />

And I have this controller:

import java.util.Date;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
@RequestMapping("/**")
public class MainController {

    @RequestMapping(method = RequestMethod.GET)
    public String service(final HttpServletRequest request) {
        final String servlet_path = request.getServletPath();
        System.out.println(String.format("%s %s", new Date().toString(), servlet_path));
        return "test";
    }
}

Now when I hit “/” or “/test” or “/test/page” I get output like:

Fri Aug 03 00:22:12 IDT 2012 /
Fri Aug 03 00:22:13 IDT 2012 /favicon.ico

.. see? service() is being called for /favicon.ico even when it’s explicitly excluded!

Now I guess there’s some “priority” to the @Controller over the XML, still, how do I make the exclusion work?

A simple requirement – have the website on “/”.

P.S This answer answers to a very similar question.

Another note: This question is not about tomcat context.

  • 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-09T03:08:09+00:00Added an answer on June 9, 2026 at 3:08 am

    The issue here is that the underlying HandlerMapping registered with <mvc:resources has a very low priority compared to the one registered with <mvc:annotation-driven/>. If you requirement is to simply have something respond to “/” a better way probably will be to have a different @RequestMapping than /** instead say have it as /home and define something along these lines:

    <mvc:view-controller path="/" view-name="home" />

    If this will not work, the only other option will be to lower the priority of underlying handlerMapping of <mvc:resources, which can be done by explicitly defining the HandlerMapping – a little complicated but can be done.

    Updated
    Here is a possible configuration:

    Try with just this first:

    <mvc:resources mapping="/favicon.ico" location="/favicon.ico" order="0"/>
    <mvc:resources mapping="/robots.txt" location="/robots.txt" order="0"/>
    

    If this alone does not work, change <mvc:annotation-driven/> to something along these lines for Spring 3.1.x:

    <bean name="handlerAdapter" class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
        <property name="webBindingInitializer">
            <bean class="org.springframework.web.bind.support.ConfigurableWebBindingInitializer">
                <property name="conversionService" ref="conversionService"></property>
                <property name="validator">
                    <bean class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean">
                        <property name="providerClass" value="org.hibernate.validator.HibernateValidator"></property>
                    </bean>
                </property>
            </bean>
        </property>
        <property name="messageConverters">
            <list>
                <bean class="org.springframework.http.converter.ByteArrayHttpMessageConverter"></bean>
                <bean class="org.springframework.http.converter.StringHttpMessageConverter"></bean>
                <bean class="org.springframework.http.converter.ResourceHttpMessageConverter"></bean>
                <bean class="org.springframework.http.converter.xml.SourceHttpMessageConverter"></bean>
                <bean class="org.springframework.http.converter.xml.XmlAwareFormHttpMessageConverter"></bean>
                <bean class="org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter"></bean>
                <bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"></bean>
            </list>
        </property>
    </bean>
    
    <bean name="handlerMapping" class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping">
        <property name="order" value="2"></property>
    </bean>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing my application using spring-web-mvc... Now at my Controller it returns like
I'm trying to inject a Map into a Grails controller. I want to inject
I want to generate raw xml from a REST service using Spring. Something is
I want to Pass 'Map' to an PL/SQL Stored Procedure via Spring Mybatis Mapper
I want to use Spring Security, and it says to map the filter to
Hi im new to this Spring , MVC and JdBC support. I want to
I want to enable my Spring MVC web application to return models' state represented
When I use spring mvc, I use <mvc:resources /> to map the location of
If i have a stl map from string to int and i want to
I want my request parameter map in my custom map like Map<String, String> reqMap

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.