您的位置:首页 > 编程语言 > Java开发

共同学习SpringMVC源码--DispatcherServlet(二)

2016-06-01 21:58 393 查看
private static final Properties defaultStrategies;

这个静态final的Properties类是默认策略,所谓默认策略就是同一包下有个DispatcherServlet.properties文件,里面定义了一些属性,其实就是一些处理器的实现类的类名。

static {
// Load default strategy implementations from properties file.
// This is currently strictly internal and not meant to be customized
// by application developers.
try {
ClassPathResource resource = new ClassPathResource(DEFAULT_STRATEGIES_PATH, DispatcherServlet.class);
defaultStrategies = PropertiesLoaderUtils.loadProperties(resource);
}
catch (IOException ex) {
throw new IllegalStateException("Could not load 'DispatcherServlet.properties': " + ex.getMessage());
}
}

这个静态块就是加载上面说的那个配置文件。

/** Detect all HandlerMappings or just expect "handlerMapping" bean? */

private boolean detectAllHandlerMappings = true;

/** Detect all HandlerAdapters or just expect "handlerAdapter" bean? */

private boolean detectAllHandlerAdapters = true;

/** Detect all HandlerExceptionResolvers or just expect "handlerExceptionResolver" bean? */

private boolean detectAllHandlerExceptionResolvers = true;

/** Detect all ViewResolvers or just expect "viewResolver" bean? */

private boolean detectAllViewResolvers = true;

这些boolean变量代表是否检测所有变量名中detect之后的组件,true代表要检测所有,false的话只检测是不是有变量名中detect之后的那个bean。

/** Throw a NoHandlerFoundException if no Handler was found to process this request? **/

private boolean throwExceptionIfNoHandlerFound = false;

这个boolean变量代表如果没有找到handler,就抛异常,默认为false,也就是不抛异常。

/** Perform cleanup of request attributes after include request? */

private boolean cleanupAfterInclude = true;

这个boolean变量代表include方法调用后是否清楚request的属性。执行include方法的servlet执行完后,再返回到原来的servlet执行response的输出(如果有),就是PrintWriter在转发后仍然会继续输出,如果有要输出内容的话。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: