{"id":11494,"date":"2023-11-28T22:20:08","date_gmt":"2023-11-28T14:20:08","guid":{"rendered":"https:\/\/wx.kaifamiao.info\/?p=11494"},"modified":"2023-12-11T10:58:29","modified_gmt":"2023-12-11T02:58:29","slug":"spring-zhongapplicationcontext-tong-chang-de-shi-x","status":"publish","type":"post","link":"http:\/\/wx.kaifamiao.info\/index.php\/2023\/11\/28\/spring-zhongapplicationcontext-tong-chang-de-shi-x\/","title":{"rendered":"Spring\u4e2dApplicationContext\u901a\u5e38\u7684\u5b9e\u73b0\u662f\u4ec0\u4e48\uff1f"},"content":{"rendered":"<p>\u5728Spring\u6846\u67b6\u4e2d\uff0c<code>ApplicationContext<\/code>\u63a5\u53e3\u6709\u591a\u79cd\u5b9e\u73b0\uff0c\u5e38\u7528\u7684\u5b9e\u73b0\u5305\u62ec\uff1a<\/p>\n<ol>\n<li>\n<strong>ClassPathXmlApplicationContext\uff1a<\/strong><\/p>\n<ul>\n<li>\u4ece\u7c7b\u8def\u5f84\u4e0b\u7684XML\u914d\u7f6e\u6587\u4ef6\u4e2d\u52a0\u8f7d\u4e0a\u4e0b\u6587\u5b9a\u4e49\uff0c\u9002\u7528\u4e8e\u57fa\u4e8eXML\u914d\u7f6e\u7684\u9879\u76ee\u3002<\/li>\n<\/ul>\n<pre><code class=\"language-java\">ApplicationContext context = new ClassPathXmlApplicationContext(&quot;applicationContext.xml&quot;);\n<\/code><\/pre>\n<\/li>\n<li>\n<strong>FileSystemXmlApplicationContext\uff1a<\/strong><\/p>\n<ul>\n<li>\u4ece\u6587\u4ef6\u7cfb\u7edf\u4e2d\u7684XML\u914d\u7f6e\u6587\u4ef6\u4e2d\u52a0\u8f7d\u4e0a\u4e0b\u6587\u5b9a\u4e49\uff0c\u9002\u7528\u4e8e\u57fa\u4e8eXML\u914d\u7f6e\u7684\u9879\u76ee\u3002<\/li>\n<\/ul>\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>AnnotationConfigApplicationContext\uff1a<\/strong><\/p>\n<ul>\n<li>\u4eceJava\u914d\u7f6e\u7c7b\u4e2d\u52a0\u8f7d\u4e0a\u4e0b\u6587\u5b9a\u4e49\uff0c\u9002\u7528\u4e8e\u57fa\u4e8e\u6ce8\u89e3\u7684\u9879\u76ee\u3002<\/li>\n<\/ul>\n<pre><code class=\"language-java\">ApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class);\n<\/code><\/pre>\n<\/li>\n<li>\n<strong>GenericWebApplicationContext\uff1a<\/strong><\/p>\n<ul>\n<li>\u901a\u7528\u7684Web\u5e94\u7528\u7a0b\u5e8f\u4e0a\u4e0b\u6587\u5b9e\u73b0\uff0c\u53ef\u4ee5\u7528\u4e8e\u57fa\u4e8eXML\u6216\u6ce8\u89e3\u7684\u914d\u7f6e\u3002<\/li>\n<\/ul>\n<pre><code class=\"language-java\">GenericWebApplicationContext context = new GenericWebApplicationContext();\ncontext.load(&quot;classpath:applicationContext.xml&quot;);\ncontext.refresh();\n<\/code><\/pre>\n<\/li>\n<li>\n<strong>GenericApplicationContext\uff1a<\/strong><\/p>\n<ul>\n<li>\u901a\u7528\u7684\u5e94\u7528\u7a0b\u5e8f\u4e0a\u4e0b\u6587\u5b9e\u73b0\uff0c\u53ef\u4ee5\u7528\u4e8e\u57fa\u4e8eXML\u6216\u6ce8\u89e3\u7684\u914d\u7f6e\u3002<\/li>\n<\/ul>\n<pre><code class=\"language-java\">GenericApplicationContext context = new GenericApplicationContext();\ncontext.load(&quot;classpath:applicationContext.xml&quot;);\ncontext.refresh();\n<\/code><\/pre>\n<\/li>\n<li>\n<strong>XmlWebApplicationContext\uff1a<\/strong><\/p>\n<ul>\n<li>\u4eceWeb\u5e94\u7528\u7a0b\u5e8f\u7684XML\u914d\u7f6e\u6587\u4ef6\u4e2d\u52a0\u8f7d\u4e0a\u4e0b\u6587\u5b9a\u4e49\uff0c\u9002\u7528\u4e8e\u57fa\u4e8eXML\u914d\u7f6e\u7684Web\u9879\u76ee\u3002<\/li>\n<\/ul>\n<pre><code class=\"language-java\">ApplicationContext context = new XmlWebApplicationContext();\n((XmlWebApplicationContext) context).setConfigLocation(&quot;\/WEB-INF\/applicationContext.xml&quot;);\n<\/code><\/pre>\n<\/li>\n<\/ol>\n<p>\u8fd9\u4e9b\u5b9e\u73b0\u63d0\u4f9b\u4e86\u4e0d\u540c\u7684\u65b9\u5f0f\u6765\u52a0\u8f7d\u548c\u914d\u7f6eSpring\u4e0a\u4e0b\u6587\uff0c\u53ef\u4ee5\u6839\u636e\u9879\u76ee\u7684\u9700\u6c42\u9009\u62e9\u9002\u5408\u7684\u5b9e\u73b0\u3002\u5176\u4e2d\uff0cClassPathXmlApplicationContext\u548cAnnotationConfigApplicationContext\u662f\u4e24\u4e2a\u5e38\u7528\u7684\u5b9e\u73b0\uff0c\u5206\u522b\u7528\u4e8e\u57fa\u4e8eXML\u548c\u6ce8\u89e3\u7684\u914d\u7f6e\u65b9\u5f0f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728Spring\u6846\u67b6\u4e2d\uff0cApplicationContext\u63a5\u53e3\u6709\u591a\u79cd\u5b9e\u73b0\uff0c\u5e38\u7528\u7684\u5b9e\u73b0\u5305\u62ec\uff1a ClassPath [&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-11494","post","type-post","status-publish","format-standard","hentry","category-spring"],"_links":{"self":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/11494","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=11494"}],"version-history":[{"count":2,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/11494\/revisions"}],"predecessor-version":[{"id":17056,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/11494\/revisions\/17056"}],"wp:attachment":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/media?parent=11494"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/categories?post=11494"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/tags?post=11494"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}