{"id":5795,"date":"2024-04-15T23:53:31","date_gmt":"2024-04-15T15:53:31","guid":{"rendered":"http:\/\/zyg.luchers.cn\/?p=5795"},"modified":"2024-04-15T23:53:31","modified_gmt":"2024-04-15T15:53:31","slug":"%e7%ac%ac%e5%85%ab%e7%ab%a0%e3%80%81%e8%b5%84%e6%ba%90%e6%93%8d%e4%bd%9cresources","status":"publish","type":"post","link":"http:\/\/zyg.luchers.cn\/index.php\/2024\/04\/15\/%e7%ac%ac%e5%85%ab%e7%ab%a0%e3%80%81%e8%b5%84%e6%ba%90%e6%93%8d%e4%bd%9cresources\/","title":{"rendered":"\u7b2c\u516b\u7ae0\u3001\u8d44\u6e90\u64cd\u4f5cResources"},"content":{"rendered":"<h1>\u7b2c\u516b\u7ae0\u3001\u8d44\u6e90\u64cd\u4f5cResources<\/h1>\n<h2>1\u3001\u6982\u8ff0<\/h2>\n<p>1\u3001\u6982\u5ff5<\/p>\n<p>Java\u7684\u6807\u51c6java.net.URL\u7c7b\u548c\u5404\u79cdURL\u524d\u7f00\u7684\u6807\u51c6\u5904\u7406\u7a0b\u5e8f\u65e0\u6cd5\u6ee1\u8db3\u6240\u6709\u5bf9low-level\u8d44\u6e90\u7684\u8bbf\u95ee\uff0c\u6bd4\u5982\uff1a\u6ca1\u6709\u6807\u51c6\u5316\u7684 URL \u5b9e\u73b0\u53ef\u7528\u4e8e\u8bbf\u95ee\u9700\u8981\u4ece\u7c7b\u8def\u5f84\u6216\u76f8\u5bf9\u4e8e ServletContext \u83b7\u53d6\u7684\u8d44\u6e90\u3002\u5e76\u4e14\u7f3a\u5c11\u67d0\u4e9bSpring\u6240\u9700\u8981\u7684\u529f\u80fd\uff0c\u4f8b\u5982\u68c0\u6d4b\u67d0\u8d44\u6e90\u662f\u5426\u5b58\u5728\u7b49\u3002**\u800cSpring\u7684Resource\u58f0\u660e\u4e86\u8bbf\u95eelow-level\u8d44\u6e90\u7684\u80fd\u529b\u3002<\/p>\n<h2>2\u3001Resource\u7684\u63a5\u53e3<\/h2>\n<p>1\u3001\u5185\u5bb9\uff1aSpring \u7684 Resource \u63a5\u53e3\u4f4d\u4e8e org.springframework.core.io \u4e2d\u3002 \u65e8\u5728\u6210\u4e3a\u4e00\u4e2a\u66f4\u5f3a\u5927\u7684\u63a5\u53e3\uff0c\u7528\u4e8e\u62bd\u8c61\u5bf9\u4f4e\u7ea7\u8d44\u6e90\u7684\u8bbf\u95ee\u3002\u4ee5\u4e0b\u663e\u793a\u4e86Resource\u63a5\u53e3\u5b9a\u4e49\u7684\u65b9\u6cd5<\/p>\n<p>2\u3001\u7ed3\u6784<\/p>\n<pre><code class=\"language-java\">public interface Resource extends InputStreamSource {\n\n    boolean exists();\n\n    boolean isReadable();\n\n    boolean isOpen();\n\n    boolean isFile();\n\n    URL getURL() throws IOException;\n\n    URI getURI() throws IOException;\n\n    File getFile() throws IOException;\n\n    ReadableByteChannel readableChannel() throws IOException;\n\n    long contentLength() throws IOException;\n\n    long lastModified() throws IOException;\n\n    Resource createRelative(String relativePath) throws IOException;\n\n    String getFilename();\n\n    String getDescription();\n}<\/code><\/pre>\n<p>3\u3001Resource\u63a5\u53e3\u7ee7\u627f\u4e86InputStreamSource\u63a5\u53e3\uff0c\u63d0\u4f9b\u4e86\u5f88\u591aInputStreamSource\u6240\u6ca1\u6709\u7684\u65b9\u6cd5\u3002InputStreamSource\u63a5\u53e3\uff0c\u53ea\u6709\u4e00\u4e2a\u65b9\u6cd5\uff1a<\/p>\n<pre><code class=\"language-java\">public interface InputStreamSource {\n\n    InputStream getInputStream() throws IOException;\n\n}<\/code><\/pre>\n<p>4\u3001\u91cd\u8981\u7684\u65b9\u6cd5 <\/p>\n<table>\n<thead>\n<tr>\n<th>\u65b9\u6cd5<\/th>\n<th>\u4f5c\u7528<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>getInputStream()<\/td>\n<td>\u627e\u5230\u5e76\u6253\u5f00\u8d44\u6e90\uff0c\u8fd4\u56de\u4e00\u4e2aInputStream\u4ee5\u4ece\u8d44\u6e90\u4e2d\u8bfb\u53d6\uff0c\u9884\u8ba1\u6bcf\u6b21\u8c03\u7528\u90fd\u4f1a\u8fd4\u56de\u4e00\u4e2a\u65b0\u7684InputStream(),\u8c03\u7528\u8005\u6709\u8d23\u4efb\u5173\u95ed\u6bcf\u4e2a\u6d41<\/td>\n<\/tr>\n<tr>\n<td>exists()<\/td>\n<td>\u8fd4\u56de\u4e00\u4e2a\u5e03\u5c14\u503c\uff0c\u8868\u660e\u67d0\u4e2a\u8d44\u6e90\u662f\u5426\u4ee5\u7269\u7406\u5f62\u5f0f\u5b58\u5728<\/td>\n<\/tr>\n<tr>\n<td>isOpen()<\/td>\n<td>\u8fd4\u56de\u4e00\u4e2a\u5e03\u5c14\u503c\uff0c\u6307\u793a\u6b64\u8d44\u6e90\u662f\u5426\u5177\u6709\u5f00\u53d1\u6d41\u7684\u53e5\u67c4\u3002\u5982\u679ctrue\uff0cInputStream\u5c31\u4e0d\u80fd\u591f\u591a\u6b21\u8bfb\u53d6\uff0c\u53ea\u80fd\u8bfb\u53d6\u4e00\u6b21\u5e76\u4e14\u53ca\u65f6\u5173\u95ed\u4ee5\u907f\u514d\u5185\u5b58\u6cc4\u6f0f\u3002\u5bf9\u4e8e\u6240\u6709\u5e38\u89c4\u8d44\u6e90\u5b9e\u73b0\uff0c\u8fd4\u56defalse\uff0c\u4f46\u662fInputStreamResource\u9664\u5916<\/td>\n<\/tr>\n<tr>\n<td>getDescription()<\/td>\n<td>\u8fd4\u56de\u8d44\u6e90\u7684\u63cf\u8ff0\uff0c\u7528\u6765\u8f93\u51fa\u9519\u8bef\u7684\u65e5\u5fd7\uff0c\u8fd9\u901a\u5e38\u662f\u5b8c\u5168\u9650\u5b9a\u7684\u6587\u4ef6\u540d\u6216\u8d44\u6e90\u7684\u5b9e\u9645URL<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>5\u3001\u5176\u4ed6\u65b9\u6cd5<\/p>\n<table>\n<thead>\n<tr>\n<th>\u65b9\u6cd5<\/th>\n<th>\u4f5c\u7528<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>isReadable()<\/td>\n<td>\u8868\u540d\u8d44\u6e90\u7684\u76ee\u5f55\u8bfb\u53d6<\/td>\n<\/tr>\n<tr>\n<td>isFile()<\/td>\n<td>\u8868\u660e\u8fd9\u4e2a\u8d44\u6e90\u662f\u5426\u4ee3\u8868\u4e86\u4e00\u4e2a\u6587\u4ef6\u7cfb\u7edf\u7684\u6587\u4ef6<\/td>\n<\/tr>\n<tr>\n<td>getURL()<\/td>\n<td>\u8fd4\u56de\u4e00\u4e2aURL\u53e5\u67c4\uff0c\u5982\u679c\u8d44\u6e90\u4e0d\u80fd\u591f\u88ab\u89e3\u6790URL\uff0c\u5c06\u629b\u51faIOException<\/td>\n<\/tr>\n<tr>\n<td>getURI()<\/td>\n<td>\u8fd4\u56de\u4e00\u4e2a\u8d44\u6e90\u7684URI\u53e5\u67c4<\/td>\n<\/tr>\n<tr>\n<td>getFile()<\/td>\n<td>\u8fd4\u56de\u67d0\u4e2a\u6587\u4ef6\uff0c\u5982\u679c\u8d44\u6e90\u4e0d\u80fd\u7891\u989d\u89e3\u6790\u6210\u4e3a\u7edd\u5bf9\u8def\u5f84\uff0c\u5219\u4f1a\u629b\u51faFileNotFoundException\u5f02\u5e38<\/td>\n<\/tr>\n<tr>\n<td>lastModified()<\/td>\n<td>\u8d44\u6e90\u6700\u540e\u4e00\u6b21\u4fee\u6539\u7684\u65f6\u95f4\u6233<\/td>\n<\/tr>\n<tr>\n<td>createRelative()<\/td>\n<td>\u521b\u5efa\u6b64\u8d44\u6e90\u7684\u76f8\u5173\u8d44\u6e90<\/td>\n<\/tr>\n<tr>\n<td>getFilename()<\/td>\n<td>\u8d44\u6e90\u7684\u6587\u4ef6\u540d\u662f\u4ec0\u4e48<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>3\u3001Resource\u7684\u5b9e\u73b0\u7c7b<\/h2>\n<h3>1\u3001\u5185\u5bb9<\/h3>\n<p>Resource \u63a5\u53e3\u662f Spring \u8d44\u6e90\u8bbf\u95ee\u7b56\u7565\u7684\u62bd\u8c61\uff0c\u5b83\u672c\u8eab\u5e76\u4e0d\u63d0\u4f9b\u4efb\u4f55\u8d44\u6e90\u8bbf\u95ee\u5b9e\u73b0\uff0c\u5177\u4f53\u7684\u8d44\u6e90\u8bbf\u95ee\u7531\u8be5\u63a5\u53e3\u7684\u5b9e\u73b0\u7c7b\u5b8c\u6210\u2014\u2014\u6bcf\u4e2a\u5b9e\u73b0\u7c7b\u4ee3\u8868\u4e00\u79cd\u8d44\u6e90\u8bbf\u95ee\u7b56\u7565\u3002Resource\u4e00\u822c\u5305\u62ec\u8fd9\u4e9b\u5b9e\u73b0\u7c7b\uff1aUrlResource\u3001ClassPathResource\u3001FileSystemResource\u3001ServletContextResource\u3001InputStreamResource\u3001ByteArrayResource<\/p>\n<h3>2\u3001URIResource\u8bbf\u95ee\u7f51\u7edc\u8d44\u6e90<\/h3>\n<h4>1\u3001\u5185\u5bb9<\/h4>\n<p>1\u3001Resource\u7684\u5b9e\u73b0\u7c7b\uff0c\u7528\u6765\u8bbf\u95ee\u7f51\u7edc\u8d44\u6e90\uff0c\u652f\u6301URL\u7684\u7edd\u5bf9\u8def\u5f84<\/p>\n<p>2\u3001file: ------\u8be5\u524d\u7f00\u7528\u4e8e\u4ece\u6587\u4ef6\u7cfb\u7edf\u4e2d\u8bfb\u53d6\u8d44\u6e90<\/p>\n<p>3\u3001http:------\u8be5\u524d\u7f00\u7528\u4e8e\u8bbf\u95ee\u57fa\u4e8eHTTP\u534f\u8bae\u7684\u7f51\u7edc\u8d44\u6e90\u3002<\/p>\n<p>4\u3001\uff08\u4e86\u89e3\uff09ftp:------\u8be5\u524d\u7f00\u7528\u4e8e\u8bbf\u95ee\u57fa\u4e8eFTP\u534f\u8bae\u7684\u7f51\u7edc\u8d44\u6e90<\/p>\n<h4>2\u3001\u5b9e\u9a8c<\/h4>\n<p>1\u3001\u521b\u5efa\u4e00\u4e2amaven\u5b50\u6a21\u5757spring6-resources<\/p>\n<p>2\u3001\u521b\u5efaUrlResourceDemo.java<\/p>\n<pre><code class=\"language-java\">package com.atqt.spring6.resources;\n\nimport org.springframework.core.io.UrlResource;\n\npublic class UrlResourceDemo {\n    public static void main(String[] args) {\n\/\/        http\u524d\u7f00\n        loadUrlResource(&quot;http:\/\/www.baidu.com&quot;);\n\/\/        file\u524d\u7f00\n        loadUrlResource(&quot;file:atqt.txt&quot;);\n    }\n\n\/\/    \u8bbf\u95ee\u524d\u7f00http\u3001file\n    public static void loadUrlResource(String path){\n\/\/        \u521b\u5efaResource\u5b9e\u73b0\u7c7b\u7684\u5bf9\u8c61UrlResource\n        try {\n            UrlResource url = new UrlResource(path);\n\/\/            \u83b7\u53d6\u8f93\u51fa\u4fe1\u606f\n            System.out.println(url.getFilename());\n            System.out.println(url.getURI());\n            System.out.println(url.getDescription());\n            System.out.println(url.getInputStream().read());\n        }catch (Exception e){\n            e.printStackTrace();\n        }\n    }\n}\n<\/code><\/pre>\n<p>3\u3001\u5176\u4e2d\u6587\u4ef6\u4e00\u5b9a\u8981\u5728\u8ddf\u76ee\u5f55\u4e0b<\/p>\n<h3>3\u3001ClassPathResource\u8bbf\u95ee\u7c7b\u8def\u5f84\u4e0b\u8d44\u6e90<\/h3>\n<h4>1\u3001\u5185\u5bb9<\/h4>\n<p>1\u3001ClassPathResource \u7528\u6765\u8bbf\u95ee\u7c7b\u52a0\u8f7d\u8def\u5f84\u4e0b\u7684\u8d44\u6e90\uff0c\u76f8\u5bf9\u4e8e\u5176\u4ed6\u7684 Resource \u5b9e\u73b0\u7c7b\uff0c\u5176\u4e3b\u8981\u4f18\u52bf\u662f\u65b9\u4fbf\u8bbf\u95ee\u7c7b\u52a0\u8f7d\u8def\u5f84\u91cc\u7684\u8d44\u6e90\uff0c\u5c24\u5176\u5bf9\u4e8e Web \u5e94\u7528\uff0cClassPathResource \u53ef\u81ea\u52a8\u641c\u7d22\u4f4d\u4e8e classes \u4e0b\u7684\u8d44\u6e90\u6587\u4ef6\uff0c\u65e0\u987b\u4f7f\u7528\u7edd\u5bf9\u8def\u5f84\u8bbf\u95ee<\/p>\n<h4>2\u3001\u5b9e\u9a8c\uff1a\u5728\u8def\u5f84\u4e0b\u521b\u5efa\u6587\u4ef6atqt.txt,\u4f7f\u7528ClassPathResource\u8bbf\u95ee<\/h4>\n<p>1\u3001\u5c31\u662f\u5728\u76f8\u5bf9resources\u6587\u4ef6\u5939\u4e2d\u51c6\u5907\u4e00\u4e2a\u6587\u4ef6\uff0c\u4f7f\u7528ClassPathResource\u53bb\u8bfb\u53d6<\/p>\n<p>2\u3001\u521b\u5efaClassPathResourceDemo\u7c7b<\/p>\n<pre><code class=\"language-java\">package com.atqt.spring6.resources;\n\nimport org.springframework.core.io.ClassPathResource;\n\nimport java.io.IOException;\nimport java.io.InputStream;\n\n\/\/\u8bbf\u95ee\u7c7b\u8def\u5f84\u4e0b\u7684\u8d44\u6e90\npublic class ClassPathResourceDemo {\n    public static void main(String[] args) {\n        loadClassPathResource(&quot;atqt.txt&quot;);\n    }\n\n    public static void loadClassPathResource(String  path){\n\/\/        \u521b\u5efa\u5bf9\u8c61ClassPathResource\n        ClassPathResource resource = new ClassPathResource(path);\n        System.out.println(resource.getFilename());\n        System.out.println(resource.getDescription());\n\/\/        \u83b7\u53d6\u6587\u4ef6\u7684\u5185\u5bb9\n        InputStream in = null;\n        try {\n            in = resource.getInputStream();\n            byte [] b = new byte[1024];\n            while(in.read(b)!=-1){\n                System.out.println(new String(b));\n            }\n        } catch (IOException e) {\n            throw new RuntimeException(e);\n        }\n\n    }\n}\n<\/code><\/pre>\n<p>3\u3001\u51c6\u5907atqt.txt\u6587\u4ef6<\/p>\n<pre><code>12312312312312\natqt<\/code><\/pre>\n<h3>4\u3001FileSystemResource \u8bbf\u95ee\u6587\u4ef6\u7cfb\u7edf\u8d44\u6e90<\/h3>\n<h4>1\u3001\u5185\u5bb9<\/h4>\n<p>1\u3001Spring \u63d0\u4f9b\u7684 FileSystemResource \u7c7b\u7528\u4e8e\u8bbf\u95ee\u6587\u4ef6\u7cfb\u7edf\u8d44\u6e90\uff0c\u4f7f\u7528 FileSystemResource \u6765\u8bbf\u95ee\u6587\u4ef6\u7cfb\u7edf\u8d44\u6e90\u5e76\u6ca1\u6709\u592a\u5927\u7684\u4f18\u52bf\uff0c\u56e0\u4e3a Java \u63d0\u4f9b\u7684 File \u7c7b\u4e5f\u53ef\u7528\u4e8e\u8bbf\u95ee\u6587\u4ef6\u7cfb\u7edf\u8d44\u6e90\u3002<\/p>\n<h4>2\u3001\u5b9e\u9a8c\uff1a\u4f7f\u7528FileSystemResource \u8bbf\u95ee\u6587\u4ef6\u7cfb\u7edf\u8d44\u6e90<\/h4>\n<p>1\u3001\u521b\u5efaFileSystemResource.java\u7c7b<\/p>\n<pre><code class=\"language-java\">package com.atqt.spring6.resources;\n\nimport org.springframework.core.io.FileSystemResource;\n\nimport java.io.IOException;\nimport java.io.InputStream;\n\npublic class FileSystemResourceDemo\n {\n    public static void main(String[] args) throws Exception {\n        String path = &quot;atqt.txt&quot;;\n        loadFileResource(path);\n    }\n    public static void loadFileResource(String path) throws Exception {\n\/\/        \u521b\u5efa\u5bf9\u8c61\n        FileSystemResource resource = new FileSystemResource(path);\n        System.out.println(resource.getFilename());\n        System.out.println(resource.getDescription());\n\n        InputStream in = resource.getInputStream();\n        byte[] b = new byte[1024];\n        while(in.read(b)!=-1){\n            System.out.println(new String(b));\n        }\n    }\n\n}\n<\/code><\/pre>\n<p>2\u3001\u6ce8\u610f\uff1aFileSystemResource\u5b9e\u4f8b\u53ef\u4f7f\u7528FileSystemResource\u6784\u9020\u5668\u663e\u793a\u5730\u521b\u5efa\uff0c\u4f46\u66f4\u591a\u7684\u65f6\u5019\u5b83\u90fd\u662f\u9690\u5f0f\u521b\u5efa\u3002\u6267\u884cSpring\u7684\u67d0\u4e2a\u65b9\u6cd5\u65f6\uff0c\u8be5\u65b9\u6cd5\u63a5\u53d7\u4e00\u4e2a\u4ee3\u8868\u8d44\u6e90\u8def\u5f84\u7684\u5b57\u7b26\u4e32\u53c2\u6570\uff0c\u5f53Spring\u8bc6\u522b\u8be5\u5b57\u7b26\u4e32\u53c2\u6570\u4e2d\u5305\u542bfile:\u524d\u7f00\u540e\uff0c\u7cfb\u7edf\u5c06\u4f1a\u81ea\u52a8\u521b\u5efaFileSystemResource\u5bf9\u8c61\u3002<\/p>\n<h3>5\u3001ServletContextResource<\/h3>\n<h3>1\u3001\u5185\u5bb9<\/h3>\n<p>1\u3001\u8fd9\u662fServletContext\u8d44\u6e90\u7684Resource\u5b9e\u73b0\uff0c\u5b83\u89e3\u91ca\u76f8\u5173Web\u5e94\u7528\u7a0b\u5e8f\u6839\u76ee\u5f55\u4e2d\u7684\u76f8\u5bf9\u8def\u5f84\u3002\u5b83\u59cb\u7ec8\u652f\u6301\u6d41(stream)\u8bbf\u95ee\u548cURL\u8bbf\u95ee\uff0c\u4f46\u53ea\u6709\u5728\u6269\u5c55Web\u5e94\u7528\u7a0b\u5e8f\u5b58\u6863\u4e14\u8d44\u6e90\u5b9e\u9645\u4f4d\u4e8e\u6587\u4ef6\u7cfb\u7edf\u4e0a\u65f6\u624d\u5141\u8bb8java.io.File\u8bbf\u95ee\u3002\u65e0\u8bba\u5b83\u662f\u5728\u6587\u4ef6\u7cfb\u7edf\u4e0a\u6269\u5c55\u8fd8\u662f\u76f4\u63a5\u4eceJAR\u6216\u5176\u4ed6\u5730\u65b9\uff08\u5982\u6570\u636e\u5e93\uff09\u8bbf\u95ee\uff0c\u5b9e\u9645\u4e0a\u90fd\u4f9d\u8d56\u4e8eServlet\u5bb9\u5668\u3002<\/p>\n<h3>6\u3001InputStreamResource<\/h3>\n<h4>1\u3001\u5185\u5bb9<\/h4>\n<p>1\u3001InputStreamResource \u662f\u7ed9\u5b9a\u7684\u8f93\u5165\u6d41(InputStream)\u7684Resource\u5b9e\u73b0\u3002\u5b83\u7684\u4f7f\u7528\u573a\u666f\u5728\u6ca1\u6709\u7279\u5b9a\u7684\u8d44\u6e90\u5b9e\u73b0\u7684\u65f6\u5019\u4f7f\u7528(\u611f\u89c9\u548c@Component \u7684\u9002\u7528\u573a\u666f\u5f88\u76f8\u4f3c)\u3002\u4e0e\u5176\u4ed6Resource\u5b9e\u73b0\u76f8\u6bd4\uff0c\u8fd9\u662f\u5df2\u6253\u5f00\u8d44\u6e90\u7684\u63cf\u8ff0\u7b26\u3002 \u56e0\u6b64\uff0c\u5b83\u7684isOpen()\u65b9\u6cd5\u8fd4\u56detrue\u3002\u5982\u679c\u9700\u8981\u5c06\u8d44\u6e90\u63cf\u8ff0\u7b26\u4fdd\u7559\u5728\u67d0\u5904\u6216\u8005\u9700\u8981\u591a\u6b21\u8bfb\u53d6\u6d41\uff0c\u8bf7\u4e0d\u8981\u4f7f\u7528\u5b83\u3002<\/p>\n<h3>7\u3001ByteArrayResource<\/h3>\n<h4>1\u3001\u5185\u5bb9<\/h4>\n<p>\u5b57\u8282\u6570\u7ec4\u7684Resource\u5b9e\u73b0\u7c7b\u3002\u901a\u8fc7\u7ed9\u5b9a\u7684\u6570\u7ec4\u521b\u5efa\u4e86\u4e00\u4e2aByteArrayInputStream\u3002\u5b83\u5bf9\u4e8e\u4ece\u4efb\u4f55\u7ed9\u5b9a\u7684\u5b57\u8282\u6570\u7ec4\u52a0\u8f7d\u5185\u5bb9\u975e\u5e38\u6709\u7528\uff0c\u800c\u65e0\u9700\u6c42\u52a9\u4e8e\u5355\u6b21\u4f7f\u7528\u7684InputStreamResource\u3002<\/p>\n<h3>8\u3001Resource\u7c7b\u56fe<\/h3>\n<p>1\u3001\u7ee7\u627f\u56fe\uff08\u6a21\u578b\uff09<\/p>\n<p><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='http:\/\/zyg.luchers.cn\/wp-content\/uploads\/2024\/04\/2023-11-05-15-17-05-image.png'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  decoding=\"async\" data-original=\"http:\/\/zyg.luchers.cn\/wp-content\/uploads\/2024\/04\/2023-11-05-15-17-05-image.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" \/><\/div><\/p>\n<h2>4\u3001ResourceLoader\u63a5\u53e3<\/h2>\n<h3>1\u3001\u6982\u8ff0<\/h3>\n<h4>1\u3001\u4e24\u4e2a\u6807\u5fd7\u6027\u63a5\u53e3<\/h4>\n<h5>1\u3001ResourceLoader<\/h5>\n<p>1\u3001\u8be5\u63a5\u53e3\u5b9e\u73b0\u7c7b\u7684\u5b9e\u4f8b\u53ef\u4ee5\u83b7\u5f97\u4e00\u4e2aResource\u5b9e\u4f8b<\/p>\n<h5>2\u3001ResourceLoaderAware<\/h5>\n<p>1\u3001\u8be5\u63a5\u53e3\u5c06\u83b7\u5f97\u4e00\u4e2aResourceLoader\u7684\u5f15\u7528<\/p>\n<h4>2\u3001ResourceLoader\u4e2d\u63a5\u53e3\u6709\u7684\u65b9\u6cd5Resource getResource\uff08String location\uff09<\/h4>\n<p>1\u3001\u4f5c\u7528\uff1a\u8be5\u63a5\u53e3\u4ec5\u6709\u8fd9\u4e2a\u65b9\u6cd5\uff0c\u7528\u4e8e\u8fd4\u56de\u4e00\u4e2aResource\u5b9e\u4f8b\u3002<\/p>\n<p>2\u3001ApplicationContext\u5b9e\u73b0\u7c7b\u90fd\u5b9e\u73b0ResourceLoader\u63a5\u53e3\uff0c\u56e0\u6b64ApplicationContext\u53ef\u76f4\u63a5\u83b7\u53d6Resource\u5b9e\u4f8b\u3002<\/p>\n<h3>2\u3001ResourceLoader\u603b\u7ed3<\/h3>\n<p>1\u3001Spring\u5c06\u91c7\u7528\u548cApplicationContext\u76f8\u540c\u7684\u7b56\u7565\u6765\u8bbf\u95ee\u8d44\u6e90\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u5982\u679cApplicationContext\u662fFileSystemXmlApplicationContext\uff0cres\u5c31\u662fFileSystemResource\u5b9e\u4f8b\uff1b\u5982\u679cApplicationContext\u662fClassPathXmlApplicationContext\uff0cres\u5c31\u662fClassPathResource\u5b9e\u4f8b<\/p>\n<p>2\u3001\u5f53Spring\u5e94\u7528\u9700\u8981\u8fdb\u884c\u8d44\u6e90\u8bbf\u95ee\u65f6\uff0c\u5b9e\u9645\u4e0a\u5e76\u4e0d\u9700\u8981\u76f4\u63a5\u4f7f\u7528Resource\u5b9e\u73b0\u7c7b\uff0c\u800c\u662f\u8c03\u7528ResourceLoader\u5b9e\u4f8b\u7684getResource()\u65b9\u6cd5\u6765\u83b7\u5f97\u8d44\u6e90\uff0cReosurceLoader\u5c06\u4f1a\u8d1f\u8d23\u9009\u62e9Reosurce\u5b9e\u73b0\u7c7b\uff0c\u4e5f\u5c31\u662f\u786e\u5b9a\u5177\u4f53\u7684\u8d44\u6e90\u8bbf\u95ee\u7b56\u7565\uff0c\u4ece\u800c\u5c06\u5e94\u7528\u7a0b\u5e8f\u548c\u5177\u4f53\u7684\u8d44\u6e90\u8bbf\u95ee\u7b56\u7565\u5206\u79bb\u5f00\u6765<\/p>\n<p>3\u3001\u53e6\u5916\uff0c\u4f7f\u7528ApplicationContext\u8bbf\u95ee\u8d44\u6e90\u65f6\uff0c\u53ef\u901a\u8fc7\u4e0d\u540c\u524d\u7f00\u6307\u5b9a\u5f3a\u5236\u4f7f\u7528\u6307\u5b9a\u7684ClassPathResource\u3001FileSystemResource\u7b49\u5b9e\u73b0\u7c7b<\/p>\n<p>4\u3001\u4f8b\u5b50<\/p>\n<pre><code class=\"language-java\">Resource res = ctx.getResource(&quot;calsspath:bean.xml&quot;);\nResrouce res = ctx.getResource(&quot;file:bean.xml&quot;);\nResource res = ctx.getResource(&quot;http:\/\/localhost:8080\/beans.xml&quot;);<\/code><\/pre>\n<h2>5\u3001ResourceLoaderAwaare\u63a5\u53e3<\/h2>\n<h3>1\u3001\u4ecb\u7ecd<\/h3>\n<p>1\u3001\u83b7\u5f97\u4e00\u4e2aResourceLoader\u7684\u5f15\u7528<\/p>\n<p>2\u3001\u63d0\u4f9b\u4e86\u4e00\u4e2asetResourceLoader()\u65b9\u6cd5\uff0c\u8be5\u65b9\u6cd5\u5c06\u7531Spring\u5bb9\u5668\u8d1f\u8d23\u8c03\u7528\uff0cSpring\u5bb9\u5668\u4f1a\u5c06\u4e00\u4e2aResourceLoader\u5bf9\u8c61\u4f5c\u4e3a\u8be5\u65b9\u6cd5\u7684\u53c2\u6570\u4f20\u5165<\/p>\n<p>3\u3001\u5982\u679c\u628a\u5b9e\u73b0ResourceLoaderAware\u63a5\u53e3\u7684Bean\u7c7b\u90e8\u7f72\u5728Spring\u5bb9\u5668\u4e2d\uff0cSpring\u5bb9\u5668\u4f1a\u5c06\u81ea\u8eab\u5f53\u6210ResourceLoader\u4f5c\u4e3asetResourceLoader()\u65b9\u6cd5\u7684\u53c2\u6570\u4f20\u5165\u3002\u7531\u4e8eApplicationContext\u7684\u5b9e\u73b0\u7c7b\u90fd\u5b9e\u73b0\u4e86ResourceLoader\u63a5\u53e3\uff0cSpring\u5bb9\u5668\u81ea\u8eab\u5b8c\u5168\u53ef\u4f5c\u4e3aResorceLoader\u4f7f\u7528\u3002<\/p>\n<h3>2\u3001\u6f14\u793aResourceLoaderAware\u4f7f\u7528<\/h3>\n<h4>1\u3001\u5b9e\u73b0ResourceLoaderAware\u7684\u63a5\u53e3<\/h4>\n<p>1\u3001\u521b\u5efaTestBean.java<\/p>\n<pre><code class=\"language-java\">package com.atqt.spring6.resources;\n\nimport org.springframework.context.ApplicationContext;\nimport org.springframework.context.support.ClassPathXmlApplicationContext;\nimport org.springframework.core.io.ResourceLoader;\n\npublic class Demo3 {\n    public static void main(String[] args) {\n\/\/        spring \u4f1a\u5c06ResouorceLoader\u5bf9\u8c61\u4f5c\u4e3a\u8be5\u65b9\u6cd5\u53c2\u6570\u4f20\u5165\n        ApplicationContext context = new ClassPathXmlApplicationContext(&quot;bean.xml&quot;);\n        TestBean testBean = context.getBean(&quot;testBean&quot;, TestBean.class);\n\/\/        \u83b7\u53d6ResourceLoader\u5bf9\u8c61\n        ResourceLoader resourceLoader = testBean.getResourceLoader();\n        System.out.println(resourceLoader==context);\n    }\n}\n<\/code><\/pre>\n<h4>2\u3001\u521b\u5efabean.xml\u6587\u4ef6\uff0c\u914d\u7f6eTestBean<\/h4>\n<pre><code class=\"language-xml\">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;\n&lt;beans xmlns=&quot;http:\/\/www.springframework.org\/schema\/beans&quot;\n       xmlns:xsi=&quot;http:\/\/www.w3.org\/2001\/XMLSchema-instance&quot;\n       xsi:schemaLocation=&quot;http:\/\/www.springframework.org\/schema\/beans http:\/\/www.springframework.org\/schema\/beans\/spring-beans.xsd&quot;&gt;\n\n    &lt;bean id=&quot;testBean&quot; class=&quot;com.atqt.spring6.resources.TestBean&quot;&gt;&lt;\/bean&gt;\n&lt;\/beans&gt;<\/code><\/pre>\n<h4>3\u3001\u521b\u5efaDemom3.java\u6d4b\u8bd5\u7c7b<\/h4>\n<pre><code class=\"language-java\">package com.atqt.spring6.resources;\n\nimport org.springframework.context.ApplicationContext;\nimport org.springframework.context.support.ClassPathXmlApplicationContext;\nimport org.springframework.core.io.ResourceLoader;\n\npublic class Demo3 {\n    public static void main(String[] args) {\n\/\/        spring \u4f1a\u5c06ResouorceLoader\u5bf9\u8c61\u4f5c\u4e3a\u8be5\u65b9\u6cd5\u53c2\u6570\u4f20\u5165\n        ApplicationContext context = new ClassPathXmlApplicationContext(&quot;bean.xml&quot;);\n        TestBean testBean = context.getBean(&quot;testBean&quot;, TestBean.class);\n\/\/        \u83b7\u53d6ResourceLoader\u5bf9\u8c61\n        ResourceLoader resourceLoader = testBean.getResourceLoader();\n        System.out.println(resourceLoader==context);\n    }\n}\n<\/code><\/pre>\n<h3>3\u3001\u4f7f\u7528Resource\u4f5c\u4e3a\u5c5e\u6027<\/h3>\n<h4>1\u3001\u95ee\u9898<\/h4>\n<p>1\u3001\u524d\u9762\u4ecb\u7ecd\u4e86 Spring \u63d0\u4f9b\u7684\u8d44\u6e90\u8bbf\u95ee\u7b56\u7565\uff0c\u4f46\u8fd9\u4e9b\u4f9d\u8d56\u8bbf\u95ee\u7b56\u7565\u8981\u4e48\u9700\u8981\u4f7f\u7528 Resource \u5b9e\u73b0\u7c7b\uff0c\u8981\u4e48\u9700\u8981\u4f7f\u7528 ApplicationContext \u6765\u83b7\u53d6\u8d44\u6e90\u3002\u5b9e\u9645\u4e0a\uff0c\u5f53\u5e94\u7528\u7a0b\u5e8f\u4e2d\u7684 Bean \u5b9e\u4f8b\u9700\u8981\u8bbf\u95ee\u8d44\u6e90\u65f6<\/p>\n<h4>2\u3001\u89e3\u51b3\u65b9\u6cd5<\/h4>\n<p>1\u3001\u76f4\u63a5\u5229\u7528\u4f9d\u8d56\u6ce8\u5165\u3002\u4ece\u8fd9\u4e2a\u610f\u4e49\u4e0a\u6765\u770b\uff0cSpring \u6846\u67b6\u4e0d\u4ec5\u5145\u5206\u5229\u7528\u4e86\u7b56\u7565\u6a21\u5f0f\u6765\u7b80\u5316\u8d44\u6e90\u8bbf\u95ee\uff0c\u800c\u4e14\u8fd8\u5c06\u7b56\u7565\u6a21\u5f0f\u548c IoC \u8fdb\u884c\u5145\u5206\u5730\u7ed3\u5408\uff0c\u6700\u5927\u7a0b\u5ea6\u5730\u7b80\u5316\u4e86 Spring \u8d44\u6e90\u8bbf\u95ee\u3002<\/p>\n<h4>3\u3001\u603b\u7ed3<\/h4>\n<p>\u5f52\u7eb3\u8d77\u6765\uff0c<strong>\u5982\u679c Bean \u5b9e\u4f8b\u9700\u8981\u8bbf\u95ee\u8d44\u6e90\uff0c\u6709\u5982\u4e0b\u4e24\u79cd\u89e3\u51b3\u65b9\u6848\uff1a<\/strong><\/p>\n<p>1\u3001<strong>\u4ee3\u7801\u4e2d\u83b7\u53d6 Resource \u5b9e\u4f8b\u3002<\/strong><\/p>\n<p>2\u3001<strong>\u4f7f\u7528\u4f9d\u8d56\u6ce8\u5165\u3002<\/strong><\/p>\n<h4>4\u3001\u5b9e\u9a8c\u4e00\uff1a\u8ba9Spring\u4e3aBean\u5b9e\u4f8b\u4f9d\u8d56\u6ce8\u5165\u8d44\u6e90<\/h4>\n<p>1\u3001\u521b\u5efa\u4f9d\u8d56\u6ce8\u5165\u7684\u7c7b\u3001\u5b9a\u4e49\u5c5e\u6027\u548c\u65b9\u6cd5<\/p>\n<h5>1\u3001\u521b\u5efaResourceBean.java<\/h5>\n<pre><code class=\"language-java\">package com.atqt.spring6.resources.di;\n\nimport org.springframework.core.io.Resource;\n\npublic class ResourceBean {\n    private Resource resource;\n\n    public Resource getResource() {\n        return resource;\n    }\n\n    public void setResource(Resource resource) {\n        this.resource = resource;\n    }\n\n    public void pares(){\n        System.out.println(resource.getFilename());\n        System.out.println(resource.getDescription());\n    }\n}\n<\/code><\/pre>\n<h5>2\u3001\u521b\u5efaspring\u914d\u7f6e\u6587\u4ef6\uff0c\u914d\u7f6e\u4f9d\u8d56\u6ce8\u5165<\/h5>\n<pre><code class=\"language-xml\">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;\n&lt;beans xmlns=&quot;http:\/\/www.springframework.org\/schema\/beans&quot;\n       xmlns:xsi=&quot;http:\/\/www.w3.org\/2001\/XMLSchema-instance&quot;\n       xsi:schemaLocation=&quot;http:\/\/www.springframework.org\/schema\/beans http:\/\/www.springframework.org\/schema\/beans\/spring-beans.xsd&quot;&gt;\n    &lt;bean id=&quot;resourceBean&quot; class=&quot;com.atqt.spring6.resources.di.ResourceBean&quot;&gt;\n&lt;!--        \u628a\u8def\u5f84\u653e\u5230\u914d\u7f6e\u6587\u4ef6\u4e2d\uff0c\u5c31\u65b9\u4fbf\u6587\u4ef6\u7684\u4fee\u6539--&gt;\n        &lt;property name=&quot;resource&quot; value=&quot;classpath:atqt.txt&quot;&gt;&lt;\/property&gt;\n    &lt;\/bean&gt;\n\n&lt;\/beans&gt;<\/code><\/pre>\n<h5>3\u3001\u8fdb\u884c\u6d4b\u8bd5TestBean.java<\/h5>\n<pre><code class=\"language-java\">package com.atqt.spring6.resources.di;\n\nimport org.springframework.context.ApplicationContext;\nimport org.springframework.context.support.ClassPathXmlApplicationContext;\n\npublic class TestBean {\n    public static void main(String[] args) {\n        ApplicationContext context = new ClassPathXmlApplicationContext(&quot;beans.xml&quot;);\n        ResourceBean resourceBean = context.getBean(ResourceBean.class);\n        resourceBean.pares();\n    }\n}\n<\/code><\/pre>\n<h2>6\u3001\u5e94\u7528\u7a0b\u5e8f\u4e0a\u4e0b\u6587\u548c\u8d44\u6e90\u8def\u5f84<\/h2>\n<h3>1\u3001\u5185\u5bb9<\/h3>\n<p>1\u3001\u4e0d\u7ba1\u4ee5\u600e\u6837\u7684\u65b9\u5f0f\u521b\u5efaApplicationContext\u5b9e\u4f8b\uff0c\u90fd\u9700\u8981\u4e3aApplicationContext\u6307\u5b9a\u914d\u7f6e\u6587\u4ef6\uff0c<strong>Spring\u5141\u8bb8\u4f7f\u7528\u4e00\u4efd\u6216\u591a\u5206XML\u914d\u7f6e\u6587\u4ef6\u3002<\/strong><\/p>\n<p>2\u3001\u5f53\u7a0b\u5e8f\u521b\u5efaApplicationContext\u5b9e\u4f8b\u65f6\uff0c\u901a\u5e38\u4e5f\u662f\u4ee5Resource\u7684\u65b9\u5f0f\u6765\u8bbf\u95ee\u914d\u7f6e\u6587\u4ef6\u7684\uff0c\u6240\u4ee5ApplicationContext\u5b8c\u5168\u652f\u6301ClassPathResource\u3001FileSystemResource\u3001ServletContextResource\u7b49\u8d44\u6e90\u8bbf\u95ee\u65b9\u5f0f\u3002<\/p>\n<h3>2\u3001ApplicationContext\u5b9e\u73b0\u7c7b\u6307\u5b9a\u8bbf\u95ee\u7b56\u7565<\/h3>\n<h4>1\u3001ApplicationContext\u5b9e\u73b0\u7c7b\u6307\u5b9a\u8bbf\u95ee\u7b56\u7565<\/h4>\n<table>\n<thead>\n<tr>\n<th style=\"text-align: left;\">\u7c7b<\/th>\n<th style=\"text-align: left;\">\u65b9\u6cd5<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"text-align: left;\">ClassPathXMLApplicationContext<\/td>\n<td style=\"text-align: left;\">\u5bf9\u5e94\u4f7f\u7528ClassPathResource\u8fdb\u884c\u8d44\u6e90\u8bbf\u95ee<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\">FileSystemXmlApplicationContext<\/td>\n<td style=\"text-align: left;\">\u5bf9\u5e94\u4f7f\u7528FileSystemResource\u8fdb\u884c\u8d44\u6e90\u8bbf\u95ee<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\">XmlWebApplicationContext<\/td>\n<td style=\"text-align: left;\">\u5bf9\u5e94\u4f7f\u7528ServletContextResource\u8fdb\u884c\u8d44\u6e90\u8bbf\u95ee<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>3\u3001\u4f7f\u7528\u524d\u7f00\u6307\u5b9a\u8bbf\u95ee\u7b56\u7565<\/h3>\n<h4>1\u3001\u5b9e\u9a8c\u4e00\uff1a\u4f7f\u7528classpath\u524d\u7f00\u4f7f\u7528<\/h4>\n<p>1\u3001\u7f16\u5199TestDemo.java<\/p>\n<pre><code class=\"language-java\">package com.atqt.spring6.resources.prefix;\n\nimport com.atqt.spring6.resources.di.User;\nimport org.springframework.context.ApplicationContext;\nimport org.springframework.context.support.ClassPathXmlApplicationContext;\nimport org.springframework.core.io.Resource;\npublic class TestDemo {\n    public static void main(String[] args) {\n\/\/        \u5e73\u5e38\u662f\u6ca1\u6709classpath\u7684\uff0c\u5c31\u9ed8\u8ba4\u662f\u6307\u5b9a\u8bbf\u95ee\u7c7b\n\/\/        \u52a0\u4e86classpath\u53ef\u4ee5\u6709\u591a\u4e2a\u914d\u7f6e\u7c7b\n        ApplicationContext context = new ClassPathXmlApplicationContext(&quot;classpath:bean.xml&quot;);\n        Resource resource =context.getResource(&quot;atqt.txt&quot;);\n        System.out.println(resource.getDescription());\n\n    }\n}<\/code><\/pre>\n<h4>2\u3001\u5b9e\u9a8c\u4e8c\uff1a\u4f7f\u7528classpath\u901a\u914d\u7b26\u4f7f\u7528<\/h4>\n<h5>1\u3001classpath\u901a\u914d\u7b26<\/h5>\n<p>1\u3001classpath <em> :\u524d\u7f00\u63d0\u4f9b\u4e86\u52a0\u8f7d\u591a\u4e2aXML\u914d\u7f6e\u6587\u4ef6\u7684\u80fd\u529b\uff0c\u5f53\u4f7f\u7528classpath<\/em>:\u524d\u7f00\u6765\u6307\u5b9aXML\u914d\u7f6e\u6587\u4ef6\u65f6\uff0c\u7cfb\u7edf\u5c06\u641c\u7d22\u7c7b\u52a0\u8f7d\u8def\u5f84\uff0c\u627e\u5230\u6240\u6709\u4e0e\u6587\u4ef6\u540d\u5339\u914d\u7684\u6587\u4ef6\uff0c\u5206\u522b\u52a0\u8f7d\u6587\u4ef6\u4e2d\u7684\u914d\u7f6e\u5b9a\u4e49\uff0c\u6700\u540e\u5408\u5e76\u6210\u4e00\u4e2aApplicationContext\u3002<\/p>\n<p>2\u3001\u5f53\u4f7f\u7528classpath * :\u524d\u7f00\u65f6\uff0cSpring\u5c06\u4f1a\u641c\u7d22\u7c7b\u52a0\u8f7d\u8def\u5f84\u4e0b\u6240\u6709\u6ee1\u8db3\u8be5\u89c4\u5219\u7684\u914d\u7f6e\u6587\u4ef6\u3002<\/p>\n<p>3\u3001\u5982\u679c\u4e0d\u662f\u91c7\u7528classpath * :\u524d\u7f00\uff0c\u800c\u662f\u6539\u4e3a\u4f7f\u7528classpath:\u524d\u7f00\uff0cSpring\u5219\u53ea\u52a0\u8f7d\u7b2c\u4e00\u4e2a\u7b26\u5408\u6761\u4ef6\u7684XML\u6587\u4ef6<\/p>\n<p>4\u3001classpath <em> : \u524d\u7f00\u4ec5\u5bf9ApplicationContext\u6709\u6548\u3002\u5b9e\u9645\u60c5\u51b5\u662f\uff0c\u521b\u5efaApplicationContext\u65f6\uff0c\u5206\u522b\u8bbf\u95ee\u591a\u4e2a\u914d\u7f6e\u6587\u4ef6(\u901a\u8fc7ClassLoader\u7684getResource\u65b9\u6cd5\u5b9e\u73b0)\u3002\u56e0\u6b64\uff0cclasspath <\/em> :\u524d\u7f00\u4e0d\u53ef\u7528\u4e8eResource\u3002<\/p>\n<h5>2\u3001\u4f8b\u5b50<\/h5>\n<pre><code class=\"language-java\">package com.atqt.spring6.resources.prefix;\nimport com.atqt.spring6.resources.di.User;\nimport org.springframework.context.ApplicationContext;\nimport org.springframework.context.support.ClassPathXmlApplicationContext;\nimport org.springframework.core.io.Resource;\npublic class TestDemo {\n    public static void main(String[] args) {\n\/\/        \u5e73\u5e38\u662f\u6ca1\u6709classpath\u7684\uff0c\u5c31\u9ed8\u8ba4\u662f\u6307\u5b9a\u8bbf\u95ee\u7c7b\n\/\/        \u52a0\u4e86classpath\u53ef\u4ee5\u6709\u591a\u4e2a\u914d\u7f6e\u7c7b\n        ApplicationContext context = new ClassPathXmlApplicationContext(&quot;classpath:bean*.xml&quot;);\n        Resource resource =context.getResource(&quot;atqt.txt&quot;);\n        System.out.println(resource.getDescription());\n        User user = context.getBean(User.class);\n        System.out.println(user);\n    }\n}<\/code><\/pre>\n<h4>3\u3001\u5b9e\u9a8c\u4e09\uff1a\u901a\u914d\u7b26\u7684\u5176\u4ed6\u4f7f\u7528<\/h4>\n<h5>1\u3001\u4e00\u6b21\u6027\u52a0\u8f7d\u591a\u4e2a\u914d\u7f6e\u6587\u4ef6\u7684\u65b9\u5f0f<\/h5>\n<p>1\u3001\u6307\u5b9a\u914d\u7f6e\u6587\u4ef6\u65f6\u4f7f\u7528\u901a\u914d\u7b26<\/p>\n<pre><code class=\"language-java\">ApplicationContext ctx = new ClassPathXmlApplicationContext(&quot;classpath:bean*.xml&quot;);<\/code><\/pre>\n<h5>2\u3001Spring\u8fd0\u884cclasspath*:\u524d\u7f00\u548c\u901a\u914d\u7b26\u7ed3\u5408\u4f7f\u7528\uff1a<\/h5>\n<pre><code class=\"language-java\">ApplicationContext ctx = new ClassPathXmlApplicationContext(&quot;classpath*:bean*.xml&quot;);<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u7b2c\u516b\u7ae0\u3001\u8d44\u6e90\u64cd\u4f5cResources 1\u3001\u6982\u8ff0 1\u3001\u6982\u5ff5 Java\u7684\u6807\u51c6java.net.URL\u7c7b\u548c\u5404\u79cdURL\u524d [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-5795","post","type-post","status-publish","format-standard","hentry","category-spring-spring"],"_links":{"self":[{"href":"http:\/\/zyg.luchers.cn\/index.php\/wp-json\/wp\/v2\/posts\/5795","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/zyg.luchers.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/zyg.luchers.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/zyg.luchers.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/zyg.luchers.cn\/index.php\/wp-json\/wp\/v2\/comments?post=5795"}],"version-history":[{"count":1,"href":"http:\/\/zyg.luchers.cn\/index.php\/wp-json\/wp\/v2\/posts\/5795\/revisions"}],"predecessor-version":[{"id":5796,"href":"http:\/\/zyg.luchers.cn\/index.php\/wp-json\/wp\/v2\/posts\/5795\/revisions\/5796"}],"wp:attachment":[{"href":"http:\/\/zyg.luchers.cn\/index.php\/wp-json\/wp\/v2\/media?parent=5795"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/zyg.luchers.cn\/index.php\/wp-json\/wp\/v2\/categories?post=5795"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/zyg.luchers.cn\/index.php\/wp-json\/wp\/v2\/tags?post=5795"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}