Spring默认对象创建?

时间:2012-07-30 09:43:02

标签: spring spring-mvc

Spring是否读取了任何配置文件,知道是否要创建一些默认的开箱即用实现(HandlerMappingViewResolver等)?

1 个答案:

答案 0 :(得分:0)

是的,DispatcherServlet.properties包中的org.springframework.web.servlet就是你要找的东西。

DispatcherServlet源中的相关代码段:

 /**
  * Name of the class path resource (relative to the DispatcherServlet class)
  * that defines DispatcherServlet's default strategy names.
  */
 private static final String DEFAULT_STRATEGIES_PATH ="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());
    }
 }