Announcement Announcement Module
No announcement yet.
javax.servlet.ServletException: Could not resolve view with name... Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • javax.servlet.ServletException: Could not resolve view with name...

    I apologize in advance if I do not provide enough information as this is my first post on the forum. I have a pretty simple RESTful service implemented using Spring MVC. In this service there are two controller classes defined using the @Controller and @RequestMapping annotations. XML is used as the request/response data format for both controllers. The problem I'm seeing is that for one of the controllers everything seems to work just as expected. The other controller causes an exception indicating the view name can not be resolved. Both controllers return a ModelAndView. Some excerpts from the configuration and corresponding classes is below:

    From Controller1 (works):

    * @param body
    * @return
    @RequestMapping(method = RequestMethod.POST, value = "/priceupdate")
    public ModelAndView priceUpdateRequest(@RequestBody String body) {

    Source source = new StreamSource(new StringReader(body));
    PriceUpdateRequest priceUpdateRequest = (PriceUpdateRequest) jaxb2Mashaller.unmarshal(source);


    PriceUpdateResponse priceUpdateResponse = pricingUpdatesHandler.handlePriceUpdateRequest(pri ceUpdateRequest);

    return new ModelAndView("XmlView", BindingResult.MODEL_KEY_PREFIX + "", priceUpdateResponse);

    From Controller2:

    @RequestMapping(method = RequestMethod.POST, value = "/inventoryupdate")
    public ModelAndView priceUpdateRequest(@RequestBody String body) {

    Source source = new StreamSource(new StringReader(body));
    InventoryUpdateRequest inventoryUpdateRequest = (InventoryUpdateRequest) jaxb2Mashaller


    InventoryUpdateResponse inventoryUpdateResponse = inventoryUpdatesHandler
    .handleInventoryUpdateRequest(inventoryUpdateReque st);

    return new ModelAndView("XmlView", BindingResult.MODEL_KEY_PREFIX + "",

    From servlet config:

    <context:component-scan base-package="bb.mockws.controller" />
    <!-- To enable @RequestMapping process on type level and method level -->
    <bean class="org.springframework.web.servlet.mvc.annotat ion.DefaultAnnotationHandlerMapping" />
    <bean class="org.springframework.web.servlet.mvc.annotat ion.AnnotationMethodHandlerAdapter" />

    <!-- Declares the OXM to be JAXB and lists mapped java classes -->
    <bean id="jaxbMarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshalle r">
    <property name="classesToBeBound">
    <value>bb.mockws.model.request.InventoryUpdateRequ est</value>
    <value>bb.mockws.model.response.InventoryUpdateRes ponse</value>
    <value>bb.mockws.model.request.PriceUpdateReques t</value>
    <value>bb.mockws.model.response.PriceUpdateRespons e</value>

    <!-- Controller class for inventory update requests -->
    <bean id="inventoryUpdatesController" class="bb.mockws.controller.InventoryUpdatesContro ller">
    <property name="inventoryUpdatesDS" ref="inventoryUpdatesDS" />
    <property name="inventoryUpdatesHandler" ref="inventoryUpdatesHandler" />
    <property name="jaxb2Mashaller" ref="jaxbMarshaller" />

    <!-- Controller class for price update requests -->
    <bean id="pricingUpdatesController" class="bb.mockws.controller.PricingUpdatesControll er">
    <property name="pricingUpdatesDS" ref="pricingUpdatesDS" />
    <property name="pricingUpdatesHandler" ref="pricingUpdatesHandler" />
    <property name="jaxb2Mashaller" ref="jaxbMarshaller" />

    <!-- Defines the view as a MarshallingView for returning raw XML -->
    <bean id="XmlView" class="org.springframework.web.servlet.view.xml.Ma rshallingView">
    <constructor-arg ref="jaxbMarshaller" />

    <bean class="org.springframework.web.servlet.view.Conten tNegotiatingViewResolver">
    <property name="mediaTypes">
    <entry key="xml" value="application/xml"/>
    <property name="viewResolvers">
    <bean class="org.springframework.web.servlet.view.BeanNa meViewResolver"/>

    The second controller doesn't seem to be able to resolve the view defined in the servlet configuration (when I hit the endpoint it throws an exception: javax.servlet.ServletException: Could not resolve view with name 'XmlView' in servlet with name 'bb-mock-service') that the first seems to have no problem resolving. The view is only defined once so I'm unsure why it is working for one but not the other. Any suggestions are much appreciated.