what is a resolver
resolver [rɪ'zɒlvə] 解析器
ViewResolver
The ViewResolver provides a mapping between view names and actual views.
Map<java.lang.String, org.springframework.web.servlet.View> map = null;
{view names : actual views}
举例1:
在 Controller 中 某个方法 return "s1"
经过 处理
<bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver"> <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" /> <property name="prefix" value="/WEB-INF/jsp/" /> <property name="suffix" value=".jsp" /> </bean>
之后
DispatcherServlet:1251 - Rendering view [org.springframework.web.servlet.view.JstlView: name 's1'; URL [/WEB-INF/jsp/s1.jsp]] in DispatcherServlet with name 'dispatcher'
举例2:
PathMatchingResourcePatternResolver.class
如下
<context:component-scan base-package="cn.zno.s1" />
通过 patternResolver 处理之后
2016-10-04 10:29:17 DEBUG PathMatchingResourcePatternResolver:317 - Resolved classpath location [cn/zno/s1/] to resources [URL [file:/D:/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/zmvc/WEB-INF/classes/cn/zno/s1/]] 2016-10-04 10:29:17 DEBUG PathMatchingResourcePatternResolver:711 - Looking for matching resources in directory tree [D:\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\zmvc\WEB-INF\classes\cn\zno\s1] 2016-10-04 10:29:17 DEBUG PathMatchingResourcePatternResolver:773 - Searching directory [D:\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\zmvc\WEB-INF\classes\cn\zno\s1] for files matching pattern [D:/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/zmvc/WEB-INF/classes/cn/zno/s1/**/*.class] 2016-10-04 10:29:17 DEBUG PathMatchingResourcePatternResolver:483 - Resolved location pattern [classpath*:cn/zno/s1/**/*.class] to resources [file [D:\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\zmvc\WEB-INF\classes\cn\zno\s1\Test.class]]
最终得到pattern [classpath*:cn/zno/s1/**/*.class]
再扫描得到spring bean
resolver 的作用就是化繁为简,将简单的经过解析翻译成为最终需要的
全路径
二、视图解析器