{"id":11922,"date":"2023-11-28T22:37:57","date_gmt":"2023-11-28T14:37:57","guid":{"rendered":"https:\/\/wx.kaifamiao.info\/?p=11922"},"modified":"2023-12-11T14:41:06","modified_gmt":"2023-12-11T06:41:06","slug":"spring-shang-xia-wen-zhi-dao-ma","status":"publish","type":"post","link":"http:\/\/wx.kaifamiao.info\/index.php\/2023\/11\/28\/spring-shang-xia-wen-zhi-dao-ma\/","title":{"rendered":"Spring\u4e0a\u4e0b\u6587\u77e5\u9053\u5417\uff1f"},"content":{"rendered":"<p>\u662f\u7684\uff0c\u6211\u4e86\u89e3 Spring \u4e0a\u4e0b\u6587\uff08ApplicationContext\uff09\u3002<\/p>\n<p>\u5728 Spring \u6846\u67b6\u4e2d\uff0c\u4e0a\u4e0b\u6587\u662f\u4e00\u4e2a\u6838\u5fc3\u6982\u5ff5\uff0c\u4ee3\u8868\u4e86\u5e94\u7528\u7a0b\u5e8f\u8fd0\u884c\u65f6\u7684\u73af\u5883\u3002Spring \u4e0a\u4e0b\u6587\u662f\u4e00\u4e2a\u5bb9\u5668\uff0c\u8d1f\u8d23\u7ba1\u7406\u548c\u7ef4\u62a4\u5e94\u7528\u7a0b\u5e8f\u4e2d\u7684\u5bf9\u8c61\uff08Bean\uff09\uff0c\u5305\u62ec\u5bf9\u8c61\u7684\u521b\u5efa\u3001\u521d\u59cb\u5316\u3001\u914d\u7f6e\u548c\u9500\u6bc1\u7b49\u5de5\u4f5c\u3002\u901a\u8fc7 Spring \u4e0a\u4e0b\u6587\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u83b7\u5f97\u5bf9 Bean \u7684\u5f15\u7528\uff0c\u5e76\u5229\u7528 Spring \u6846\u67b6\u63d0\u4f9b\u7684\u529f\u80fd\uff0c\u5982\u4f9d\u8d56\u6ce8\u5165\u3001AOP\u3001\u4e8b\u52a1\u7ba1\u7406\u7b49\u3002<\/p>\n<p>Spring \u6846\u67b6\u63d0\u4f9b\u4e86\u591a\u79cd\u7c7b\u578b\u7684\u4e0a\u4e0b\u6587\uff0c\u5176\u4e2d\u6700\u5e38\u89c1\u7684\u662f\uff1a<\/p>\n<ol>\n<li>\n<strong>FileSystemXmlApplicationContext\uff1a<\/strong> \u4ece\u6587\u4ef6\u7cfb\u7edf\u52a0\u8f7d\u914d\u7f6e\u6587\u4ef6\u7684\u4e0a\u4e0b\u6587\uff0c\u901a\u8fc7\u6307\u5b9a\u6587\u4ef6\u8def\u5f84\u52a0\u8f7d Spring \u914d\u7f6e\u6587\u4ef6\u3002<\/p>\n<pre><code class=\"language-java\">ApplicationContext context = new FileSystemXmlApplicationContext(&quot;path\/to\/applicationContext.xml&quot;);\n<\/code><\/pre>\n<\/li>\n<li>\n<strong>ClassPathXmlApplicationContext\uff1a<\/strong> \u4ece\u7c7b\u8def\u5f84\uff08Classpath\uff09\u52a0\u8f7d\u914d\u7f6e\u6587\u4ef6\u7684\u4e0a\u4e0b\u6587\uff0c\u9002\u7528\u4e8e\u5728\u7c7b\u8def\u5f84\u4e0b\u7684\u9879\u76ee\u3002<\/p>\n<pre><code class=\"language-java\">ApplicationContext context = new ClassPathXmlApplicationContext(&quot;classpath:applicationContext.xml&quot;);\n<\/code><\/pre>\n<\/li>\n<li>\n<strong>AnnotationConfigApplicationContext\uff1a<\/strong> \u57fa\u4e8e\u6ce8\u89e3\u914d\u7f6e\u7684\u4e0a\u4e0b\u6587\uff0c\u901a\u8fc7 Java \u7c7b\u914d\u7f6e\uff0c\u7528\u4e8e\u4f7f\u7528\u57fa\u4e8e\u6ce8\u89e3\u7684\u914d\u7f6e\u3002<\/p>\n<pre><code class=\"language-java\">ApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class);\n<\/code><\/pre>\n<\/li>\n<li>\n<strong>GenericWebApplicationContext\uff1a<\/strong> Web \u5e94\u7528\u7a0b\u5e8f\u4e2d\u7684\u4e0a\u4e0b\u6587\uff0c\u9002\u7528\u4e8e Spring MVC \u6216 Spring Boot \u9879\u76ee\u3002<\/p>\n<pre><code class=\"language-java\">ApplicationContext context = new GenericWebApplicationContext();\n<\/code><\/pre>\n<\/li>\n<li>\n<strong>XmlWebApplicationContext\uff1a<\/strong> Web \u5e94\u7528\u7a0b\u5e8f\u4e2d\u4ece XML \u6587\u4ef6\u52a0\u8f7d\u914d\u7f6e\u7684\u4e0a\u4e0b\u6587\u3002<\/p>\n<pre><code class=\"language-java\">ApplicationContext context = new XmlWebApplicationContext();\n<\/code><\/pre>\n<\/li>\n<\/ol>\n<p>\u8fd9\u4e9b\u4e0a\u4e0b\u6587\u5b9e\u73b0\u4e0d\u540c\u7684\u52a0\u8f7d\u548c\u914d\u7f6e\u65b9\u5f0f\uff0c\u9002\u7528\u4e8e\u4e0d\u540c\u7684\u573a\u666f\u3002Spring \u4e0a\u4e0b\u6587\u8d1f\u8d23\u7ba1\u7406 Bean \u7684\u751f\u547d\u5468\u671f\uff0c\u652f\u6301\u4f9d\u8d56\u6ce8\u5165\uff0c\u63d0\u4f9b\u4e86\u5404\u79cd\u529f\u80fd\uff0c\u4f8b\u5982\u4e8b\u4ef6\u4f20\u64ad\u3001\u56fd\u9645\u5316\u3001\u8d44\u6e90\u52a0\u8f7d\u7b49\u3002\u5728 Spring \u5e94\u7528\u7a0b\u5e8f\u4e2d\uff0c\u901a\u5e38\u4f1a\u9009\u62e9\u9002\u5408\u9879\u76ee\u9700\u6c42\u7684\u4e0a\u4e0b\u6587\u7c7b\u578b\uff0c\u5e76\u5728\u6574\u4e2a\u5e94\u7528\u7a0b\u5e8f\u7684\u751f\u547d\u5468\u671f\u4e2d\u4f7f\u7528\u5b83\u6765\u7ba1\u7406\u548c\u83b7\u53d6 Bean\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u662f\u7684\uff0c\u6211\u4e86\u89e3 Spring \u4e0a\u4e0b\u6587\uff08ApplicationContext\uff09\u3002 \u5728 Spring \u6846\u67b6\u4e2d\uff0c\u4e0a\u4e0b\u6587 [&hellip;]<\/p>\n","protected":false},"author":9,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[121],"tags":[],"class_list":["post-11922","post","type-post","status-publish","format-standard","hentry","category-spring"],"_links":{"self":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/11922","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/users\/9"}],"replies":[{"embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/comments?post=11922"}],"version-history":[{"count":2,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/11922\/revisions"}],"predecessor-version":[{"id":37351,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/11922\/revisions\/37351"}],"wp:attachment":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/media?parent=11922"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/categories?post=11922"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/tags?post=11922"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}