ClassPathXmlApplicationContext和FileSystemXmlApplicationContext区别

ClassPathXmlApplicationContext
默认文件路径是src下那一级
classpath:和classpath*:的区别:
classpath: 只能加载一个配置文件,如果配置了多个,则只加载第一个
classpath*: 可以加载多个配置文件,如果有多个配置文件,就用这个

FileSystemXmlApplicationContext
这个类,默认获取的是项目路径,默认文件路径是项目名下一级,与src同级。
如果前边加了file:则说明后边的路径就要写全路径了,就是绝对路径
file:D:/workspace/applicationContext.xml


通过在spring加载的时候直接加载properties文件
<context:property-placeholder location="file:D://property/dinpay.ogg.properties" />

 

System.out.println(System.getProperty("user.dir"));

 

Linux和Windows系统识别不一致

如加载配置文件有区别

   private static AbstractApplicationContext appContext = null;
    private static final String XML_EXPRESSION = "classpath*:applicationContext*.xml";

    static {
        // 后续来读取命令中的conf 例如 java -Dconf=conf/*.xml -classpath .:lib/*
        if (System.getProperty("conf") != null) {
            appContext = new FileSystemXmlApplicationContext(System.getProperty("conf").concat("/applicationContext-sync.xml"));
        } else {
            appContext = new ClassPathXmlApplicationContext(XML_EXPRESSION);
        }
    }

 

posted @ 2017-04-21 13:11  一心行走  阅读(3047)  评论(0编辑  收藏  举报