0

I need to add Restful URL in existing spring based web service.

Each URL is well mapped but after clicking Restful URL such as http://localhost:9090/Mercury/rest/invoice, all contextroot path is changed as http://localhost:9090/Mercury/rest

The point is that I want to use both restful(/rest) and *.do URL pattern

How can I set contextroot path up without /rest ?

web.xml

     <servlet>
        <servlet-name>dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
     </servlet>
     <servlet-mapping>
        <servlet-name>dispatcher</servlet-name>
        <url-pattern>*.do</url-pattern>
     </servlet-mapping>

     <servlet>
        <servlet-name>rest</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>2</load-on-startup>
     </servlet>
     <servlet-mapping>
        <servlet-name>rest</servlet-name>
        <url-pattern>/</url-pattern>
     </servlet-mapping>

Controller

@Controller
@RequestMapping("/rest")
public class InvoiceController {

@RequestMapping(value="/{name}", method=RequestMethod.GET)
public String getInvoice(@PathVariable String name, Model model) {

    model.addAttribute("name", name);

    return "rest.body";
}
Aniket Kulkarni
  • 12,825
  • 9
  • 67
  • 90
JoonHo Kim
  • 31
  • 4

1 Answers1

0

Please refer Spring Pet Clinic on github, to learn how to configure various views.Sample view config xml. Here is the outline.

The ContentNegotiatingViewResolver delegates to the InternalResourceViewResolver and BeanNameViewResolver, and uses the requested media type (determined by the path extension) to pick a matching view. When the media type is 'text/html', it will delegate to the InternalResourceViewResolver's JstlView, otherwise to the BeanNameViewResolver.

bsingh
  • 145
  • 1
  • 6