auser
auser

Reputation: 7497

How does Spring MVC determine which .xhtml to associate with a given controller

I followed this tutorial to create a basic Spring MVC 3 and JSF 2 app. For any given Controller how does Spring MVC associate a controller with an appropriate .xhtml file. For example in the tutorial above helloWorld.xhtml is associated with the HelloWorldController. But I can't see any configuration file which creates this association.

Upvotes: 2

Views: 3678

Answers (1)

Vinny
Vinny

Reputation: 797

The magic is happening in the applicationContext.xml, this block defining the viewResolver bean in particular:

<bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
    <property name="cache" value="false" />
    <property name="viewClass" value="org.springframework.faces.mvc.JsfView" />
    <property name="prefix" value="/WEB-INF/views/" />
    <property name="suffix" value=".xhtml" />
</bean>

this part of the configuration looks in your webapp's /WEB-INF/views/ directory for .xhtml files that match the pattern of the view name that your controllers return.

Upvotes: 6

Related Questions