• 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);
            }
        }
  • 相关阅读:
    springcloud生态图
    redis持久化机制之AOF与RDB
    关键字的理解
    Java IO6 :IO总结
    Java IO5:管道流、对象流
    Java IO4:字符流进阶及BufferedWriter、BufferedReader
    Java IO3:字节流
    Java IO2:RandomAccessFile
    Java IO1:IO和File
    java学习笔记
  • 原文地址:https://www.cnblogs.com/atomicbomb/p/6743091.html
Copyright © 2020-2023  润新知