{"id":317,"date":"2022-04-09T08:54:24","date_gmt":"2022-04-09T00:54:24","guid":{"rendered":"https:\/\/blog.lijiajia.top\/?p=317"},"modified":"2026-06-19T21:38:05","modified_gmt":"2026-06-19T13:38:05","slug":"spring5%e6%a1%86%e6%9e%b6%e5%ad%a6%e4%b9%a0%ef%bc%9a%e6%96%b0%e5%8a%9f%e8%83%bd-%e5%87%bd%e6%95%b0%e5%bc%8f%e9%a3%8e%e6%a0%bc%e4%ba%8c%e5%8d%81%e4%ba%94","status":"publish","type":"post","link":"https:\/\/blog.ttwow.top\/?p=317","title":{"rendered":"Spring5\u6846\u67b6\u5b66\u4e60\uff1a\u65b0\u529f\u80fd-\u51fd\u6570\u5f0f\u98ce\u683cGenericApplicationContext(\u4e8c\u5341\u4e94)"},"content":{"rendered":"<pre><code class=\"language-java\">\/\/\u51fd\u6570\u5f0f\u98ce\u683c\u521b\u5efa\u5bf9\u8c61 \u4ea4\u7ed9spring\u7ba1\u7406\n    @Test\n    public void testGenericApplicationContext(){\n        \/\/1.\u521b\u5efaGenericApplicationContext\u5bf9\u8c61\n        GenericApplicationContext context = new GenericApplicationContext();\n        \/\/2.\u8c03\u7528context\u7684\u65b9\u6cd5\u5bf9\u8c61\u6ce8\u518c\n        context.refresh();\n        context.registerBean(&quot;user2&quot;,User.class,() -&gt;new User());\n        \/\/3.\u83b7\u53d6\u5728spring\u6ce8\u518c\u7684\u5bf9\u8c61\n        \/\/(1) \u901a\u8fc7\u7c7b \u5168\u8def\u5f84\u627e\u5230\u5bf9\u8c61\uff0cbeanName\u53ef\u4ee5\u4e3a\u7a7a \u4e0d\u4e3a\u7a7a\u65f6\uff1a\u6307\u5b9a\u83b7\u53d6\u7684\u540d\u79f0\u662f\u4ec0\u4e48\n        \/\/User user = (User) context.getBean(&quot;com.spring5.test.User&quot;);\n        \/\/(2) \u901a\u8fc7beanName\n        User user = (User) context.getBean(&quot;user2&quot;);\n        System.out.println(user);\n\n    }<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\/\/\u51fd\u6570\u5f0f\u98ce\u683c\u521b\u5efa\u5bf9\u8c61 \u4ea4\u7ed9spring\u7ba1\u7406 @Test public void testGenericApp [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[125],"tags":[68],"class_list":["post-317","post","type-post","status-publish","format-standard","hentry","category-java-backend","tag-spring"],"_links":{"self":[{"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=\/wp\/v2\/posts\/317","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=317"}],"version-history":[{"count":1,"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=\/wp\/v2\/posts\/317\/revisions"}],"predecessor-version":[{"id":2138,"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=\/wp\/v2\/posts\/317\/revisions\/2138"}],"wp:attachment":[{"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=317"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=317"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=317"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}