对于static的理解

来源:互联网 发布:c语言单竖线 编辑:程序博客网 时间:2024/05/29 03:00
今天看SpringMVC中Dispatcher源代码发现了一个static关键词的用法,因为在java中会先去加载静态变量,静态代码块,再去加载非静态变量,普通代码块。所以dispatcher中有一段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());
}

}

   去加载默认的配置。这样就可以做到,在程序启动时先去加载默认的配置,然后调用onRefresh(ApplicationContext context)方法去调用相应的方法加载自己配置的组件覆盖默认配置。

原创粉丝点击