• java Resource


    ClassPathResource:

      String resource = ""; //相对路径

      Resource resource = new ClassPathResource(resource);

      //获取当前类下,同一个包中的资源

      Resource resource = new ClassPathResource("文件名称",this.getClass());

    FileSystemResource:

      String resource = "";

      //文件系统的真实路径

       Resource resource = new FileSystemResource(resource);

    UrlResource:

        String resource = "httP://...";

          resource = "file://c:/applic...";

         Resource resource = new UrlResource("file://c:/applicationContext.xml");

    ServletContextResource:

      需要在web环境中才可以

       Resource resource = new ServletContextResource(servletContext,"/WEB-INF/classes/applicationContext.xml");

    我们在使用spring容器的时候,由于applicationContext是beanFactory子类,封装了更多方法功能供我们调用,所以在使用applicationContext时,会使用特定格式的字符串表示各种类型

    classPath:loaded from the classpath

    file:loaded as a URL,from the fileSystem

    http:  loaded as a URL

    none   /data/config.xml    Depends on the underlying ApplicationContext

  • 相关阅读:
    108.将有序数组转换成二叉搜索树
    剑指Offer 09.用两个栈实现队列
    215.数组中的第K个最大元素
    AcWing 845.八数码
    1.两数之和
    迷宫问题
    倒计时
    Redis 红包
    Redis
    EF Api 全套
  • 原文地址:https://www.cnblogs.com/cr1719/p/3841853.html
Copyright © 2020-2023  润新知