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);
        }
    }

 

相关文章:

  • 2021-12-13
  • 2021-09-22
  • 2022-12-23
  • 2021-04-05
  • 2022-12-23
  • 2022-12-23
  • 2021-06-05
  • 2021-05-20
猜你喜欢
  • 2021-07-07
  • 2022-01-10
  • 2022-02-16
  • 2022-12-23
  • 2022-12-23
  • 2021-09-19
  • 2022-12-23
相关资源
相似解决方案