Spring初始化默認轉換器

UML
這裏寫圖片描述
這裏寫圖片描述
關鍵代碼

1、啓動spring

private static void base() {
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(  
                new String[] { "classpath:applicationContext.xml" });
        context.start();
    }

2、ClassPathXmlApplicationContext中

public ClassPathXmlApplicationContext(String[] configLocations, boolean refresh, ApplicationContext parent)
            throws BeansException {

        super(parent);
        //設置默認的環境(包括默認的轉換器及對路徑表達式的解析)
        setConfigLocations(configLocations);
        if (refresh) {
            refresh();
        }
    }

3、AbstractRefreshableConfigApplicationContext中

protected String resolvePath(String path) {
        //獲取默認環境配置及轉換路徑中的表達式
        return getEnvironment().resolveRequiredPlaceholders(path);
    }

4、DefaultConversionService類中

public static void addDefaultConverters(ConverterRegistry converterRegistry) {
        addScalarConverters(converterRegistry);
        addCollectionConverters(converterRegistry);

        converterRegistry.addConverter(new ByteBufferConverter((ConversionService) converterRegistry));
        if (jsr310Available) {
            Jsr310ConverterRegistrar.registerJsr310Converters(converterRegistry);
        }

        converterRegistry.addConverter(new ObjectToObjectConverter());
        converterRegistry.addConverter(new IdToEntityConverter((ConversionService) converterRegistry));
        converterRegistry.addConverter(new FallbackObjectToStringConverter());
        if (javaUtilOptionalClassAvailable) {
            converterRegistry.addConverter(new ObjectToOptionalConverter((ConversionService) converterRegistry));
        }
    }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章