I hope it helps you, it is brief though.
It is tested in Spring 3.1 and 3.1.1 version.
context:component-scan : It will scan your java class package. which is coded in spring annotation based.
It has several ViewResolver as you see.
ContentNegotiatingViewResolver : It will show json result.if you want you can put xml,rss result view in ContentNegotiatingViewResolver.
InternalResourceViewResolver: It will show your jsp page.
SimpleUrlHandlerMapping : It will be handle if spring doesn't find any RequestMapping from Controller, the request will get to UrlFilenameViewController. it will resolve jsp file that is under /WEB-INF/jsp directory. so you don't have to make empty controller for each request mapping that doesn't have any logic.
I am sure it will trigger more curiosity if you are interested.
<context:component-scan base-package="yourpackage"/> <bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver"> <property name="order" value="1" /> <property name="mediaTypes"> <map> <entry key="json" value="application/json" /> </map> </property> <property name="defaultViews"> <list> <!-- JSON View --> <bean class="org.springframework.web.servlet.view.json.MappingJacksonJsonView"> </bean> </list> </property> <property name="ignoreAcceptHeader" value="true" /> </bean> <!-- If no extension matched, use JSP view --> <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="order" value="2" /> <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" /> <property name="prefix" value="/WEB-INF/jsp/" /> <property name="suffix" value=".jsp" /> </bean> <bean name="myController" class="org.springframework.web.servlet.mvc.UrlFilenameViewController"/> <!-- If no view matched --> <bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> <property name="mappings"> <value> /**/*.do=myController </value> </property> <property name="order" value="3" /> </bean> <!-- Configure the multipart resolver for file upload request --> <bean id="multipartResolver" class="org.springframework.web.multipart.support.StandardServletMultipartResolver" /> <!-- for rest url pattern support --> <mvc:default-servlet-handler /> <mvc:annotation-driven />
No comments:
Post a Comment