I am running simple Spring MVC application. In web.xml, I used following mapping configuration:
<servlet-mapping>
<servlet-name>spring-web</servlet-name>
<url-pattern></url-pattern> <!-- root request -->
<url-pattern>/endpoint/*</url-pattern> <!-- /endpoint/${name} -->
</servlet-mapping>
My controller is defined as:
@RequestMapping(value = "/endpoint/{name}", method = RequestMethod.GET)
public ModelAndView render(@PathVariable("name") String name) {
ModelAndView genericRenderStructure = new ModelAndView();
genericRenderStructure.setViewName("WEB-INF/views/index.jsp");
genericRenderStructure.addObject("endpointName", name);
return genericRenderStructure;
}
And yet render function is not triggered when visiting the path /endpoints/something
. When I change the url-pattern to particular variable name, like <url-pattern>/endpoint/something</url-pattern>
, the page starts working on such url. Why doesn't the wildcard symbol match my "whatever" used in url? Is this the problem with RequestMapping value? I am using Tomcat server v9.0.
web.xml
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<display-name>Spring3 MVC Application</display-name>
<servlet>
<servlet-name>spring-web</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring-web</servlet-name>
<url-pattern></url-pattern> <!-- root request -->
<url-pattern>/endpoint/*</url-pattern> <!-- /endpoint/${name} -->
</servlet-mapping>
spring-web-servlet.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd">
<context:component-scan base-package="com.api.web.*" ></context:component-scan>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/</value>
</property>
<property name="suffix">
<value></value>
</property>
</bean>
<mvc:resources mapping="/resources/**" location="/resources/" />
<mvc:annotation-driven />
</beans>