Rag
Rag

Reputation: 1433

Spring request mapping: Matching with url pattern

I have a web application with Spring MVC.

web.xml

<servlet>
    <servlet-name>spring</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>

<servlet-mapping>
    <servlet-name>spring</servlet-name>
    <url-pattern>*.do</url-pattern>
    <url-pattern>/companies/*</url-pattern>
</servlet-mapping>

spring controller method:

class RealmInfoController{

    @ResponseBody
    @RequestMapping(value = {"/companies/{companyId}/realms/{realmName}"})
    public RealmInfo realmInfo(@PathVariable long companyId, @PathVariable String realmName)

Handler match:

http://localhost:6122/context/companies/15877/realms/firstRealm

When the server gets this url, the spring servlet gets called. but it cannot match the controller method.

But if I change the request mapping to "/{companyId}/realms/{realmName}" then it matches the controller method. But it is not nice to define the url mapping without '/companies'. Can Spring be instructed in some way to look for match including the url pattern specified in the servlet?

Thanks.

Upvotes: 0

Views: 6396

Answers (1)

dyrkin
dyrkin

Reputation: 544

if you want to use "companies" in request mapping you should map your dispatcher servlet to the root:

<url-pattern>/*</url-pattern>

Upvotes: 1

Related Questions