×
☰ See All Chapters

BeanNameUrlHandlerMapping

BeanNameUrlHandlerMapping is the default URL handler used by Spring MVC. That means if we do not specify any URL handler in our Spring MVC configuration, spring will automatically load this URL handler and pass requested URls to BeanNameUrlHandlerMapping to get the controller bean to be executed. BeanNameUrlHandlerMapping defines the navigation strategy that maps the servlet-path/URI of the URL to the bean names. Using name attribute in <bean> tag is compulsory when using BeanNameUrlHandlerMapping. We have to configure the BeanNameUrlHandlerMapping explicitly in only two cases.

  1. When we want to configure multiple handler mappings along with these BeanNameUrlHandlerMapping is also one of them. 

  2. When we want to configure handler interceptors. 

beannameurlhandlermapping-0
 

BeanNameUrlHandlerMapping example

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="https://www.springframework.org/schema/beans"

        xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"

        xmlns:context="https://www.springframework.org/schema/context"

        xsi:schemaLocation="https://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd

                https://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context-5.0.7.xsd">

 

        <bean name="/disply.html" class="com.java4coding.controller.HelloController"/>

      <bean id="urlHandler" class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping"/>

</beans>

 

 


All Chapters
Author