Note that there are some explanatory texts on larger screens.

plurals
  1. POHow does Spring portlet MVC 3.1 determine which annotated method to render with multiple controllers?
    text
    copied!<p>We have encountered a problem using Spring Portlet MVC 3.1 when using multiple controller classes and the DefaultAnnotationHandlerMapping.</p> <p><strong>Background</strong></p> <ul> <li>We are using Spring Portlet MVC 3.1 with annotations for the Render &amp; Action phases</li> <li>We are using JBoss EPP 5.1.1</li> </ul> <p><strong>Issue</strong></p> <ul> <li>For a Portlet render request with params, an incorrect page is rendered in the portlet</li> </ul> <p><strong>Cause</strong></p> <ul> <li>Spring Portlet MVC is using a different method for @RenderMapping than the expected method with the correct annotations</li> </ul> <p><strong>Technical Analysis</strong></p> <ol> <li><p>All our controllers contain @RenderMapping and @ActionMapping annotations, and all have “params” arguments to ensure that the expected method is invoked based on a parameter set in our portlet URLs. For default rendering, we have a method that has a @RenderMapping annotation with no “params” argument, which we use to render a blank JSP when the request contains no parameters.</p></li> <li><p>Based on the reading of Chapter 7 and 8 in your book, we learnt that the Dispatcher Portlet tries to get the appropriate handler mapping for the incoming request and send it to the appropriate method in the controller bean configured. Our assumption was that our default @RenderMapping annotation (with no params) would only be invoked after it has checked that there are no other methods in the Controllers with an annotation that matches the specific request parameters.</p></li> <li><p>However, we have debugged to realise that this assumption is incorrect. The DefaultAnnotationHandlerMapping appears to traverse through the available list of annotations in the Controller beans in some pre-defined order. This means that if the controller bean with the default @RenderMapping annotation (with no params)appears before in the list, the method with the default @RenderMapping annotation (with no params) will be invoked rather than the correct which is further down the list.</p></li> </ol> <p><strong>Manifested Error</strong></p> <p>We are developing in a Windows environment and deploying to a Linux environment. In Windows we see that the handler cycles through the controller beans in alphabetical order, so we initially solved our problem by adding the @RenderMapping annotated method with no params in the controller with the bean name closest to ‘Z’. </p> <p>In Linux, however, it appears that the controller beans are detected in a different order. I have attached the Spring logs below to highlight the issue. The no params @RenderMapping annotation is in the YourDetailsController, and as you can see in the Windows log it appears last in the list, whereas in Linux it doesn’t. This means that if we try to access one of the controllers that appears after the YourDetailsController in the list we instead always end up hitting the no params annotation in the YourDetailsController instead.</p> <p><strong>Questions</strong></p> <ol> <li>Is our assumption incorrect?</li> <li>Does our diagnosis reflect expected behaviour? Or is it a bug with Spring Portlet MVC?</li> <li>Is there a different way to get the annotations scanned to form the handlermapping bean list?</li> <li>Would using xml configuration (instead of annotations) remove our problem?</li> <li>Would we able to define multiple handler mapping and order so that the default handler mapping is the last handler mapping used by the dispatcher portlet?</li> </ol> <p>Any thoughts or advice you have on this problem would be greatly appreciated.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload