{"id":12372,"date":"2023-11-28T22:51:50","date_gmt":"2023-11-28T14:51:50","guid":{"rendered":"https:\/\/wx.kaifamiao.info\/?p=12372"},"modified":"2023-12-11T16:58:29","modified_gmt":"2023-12-11T08:58:29","slug":"spring-zhong-ru-he-zhu-ru-yi-gejava-ji-he","status":"publish","type":"post","link":"http:\/\/wx.kaifamiao.info\/index.php\/2023\/11\/28\/spring-zhong-ru-he-zhu-ru-yi-gejava-ji-he\/","title":{"rendered":"Spring\u4e2d\u5982\u4f55\u6ce8\u5165\u4e00\u4e2aJava\u96c6\u5408\uff1f"},"content":{"rendered":"<p>\u5728Spring\u4e2d\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528<code>@Autowired<\/code>\u6ce8\u89e3\u6216\u8005\u901a\u8fc7XML\u914d\u7f6e\u6765\u6ce8\u5165Java\u96c6\u5408\u3002\u4ee5\u4e0b\u662f\u4e24\u79cd\u5e38\u89c1\u7684\u65b9\u5f0f\uff1a<\/p>\n<h3><a id=\"1%E4%BD%BF%E7%94%A8-autowired%E6%B3%A8%E8%A7%A3%EF%BC%9A\" class=\"anchor\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"><\/span><\/a>1. \u4f7f\u7528<code>@Autowired<\/code>\u6ce8\u89e3\uff1a<\/h3>\n<p>\u901a\u8fc7<code>@Autowired<\/code>\u6ce8\u89e3\uff0c\u4f60\u53ef\u4ee5\u76f4\u63a5\u5c06\u4e00\u4e2aJava\u96c6\u5408\u6ce8\u5165\u5230\u4e00\u4e2aBean\u7684\u5b57\u6bb5\u6216\u8005\u65b9\u6cd5\u53c2\u6570\u4e2d\u3002<\/p>\n<h4><a id=\"%E4%BE%8B%E5%AD%90%EF%BC%9A\" class=\"anchor\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"><\/span><\/a>\u4f8b\u5b50\uff1a<\/h4>\n<pre><code class=\"language-java\">import org.springframework.beans.factory.annotation.Autowired;\nimport org.springframework.stereotype.Component;\n\nimport java.util.List;\n\n@Component\npublic class MyBean {\n    @Autowired\n    private List&lt;String&gt; myList;\n\n    public List&lt;String&gt; getMyList() {\n        return myList;\n    }\n}\n<\/code><\/pre>\n<p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0cSpring\u4f1a\u81ea\u52a8\u5c06\u5339\u914d\u7c7b\u578b\u7684Bean\uff08\u5728\u8fd9\u91cc\u662f<code>List&lt;String&gt;<\/code>\u7c7b\u578b\u7684Bean\uff09\u6ce8\u5165\u5230<code>myList<\/code>\u5b57\u6bb5\u4e2d\u3002<\/p>\n<h3><a id=\"2%E4%BD%BF%E7%94%A8-xml%E9%85%8D%E7%BD%AE%EF%BC%9A\" class=\"anchor\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"><\/span><\/a>2. \u4f7f\u7528XML\u914d\u7f6e\uff1a<\/h3>\n<p>\u901a\u8fc7XML\u914d\u7f6e\uff0c\u4f60\u53ef\u4ee5\u663e\u5f0f\u5730\u914d\u7f6e\u4e00\u4e2aJava\u96c6\u5408\uff0c\u5e76\u5c06\u5176\u6ce8\u5165\u5230\u4e00\u4e2aBean\u4e2d\u3002<\/p>\n<h4><a id=\"%E4%BE%8B%E5%AD%90%EF%BC%9A\" class=\"anchor\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"><\/span><\/a>\u4f8b\u5b50\uff1a<\/h4>\n<pre><code class=\"language-xml\">&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\n                           http:\/\/www.springframework.org\/schema\/beans\/spring-beans.xsd&quot;&gt;\n\n    &lt;util:list id=&quot;myList&quot; list-class=&quot;java.util.ArrayList&quot;&gt;\n        &lt;value&gt;Item 1&lt;\/value&gt;\n        &lt;value&gt;Item 2&lt;\/value&gt;\n        &lt;value&gt;Item 3&lt;\/value&gt;\n    &lt;\/util:list&gt;\n\n    &lt;bean id=&quot;myBean&quot; class=&quot;com.example.MyBean&quot;&gt;\n        &lt;property name=&quot;myList&quot; ref=&quot;myList&quot;\/&gt;\n    &lt;\/bean&gt;\n&lt;\/beans&gt;\n<\/code><\/pre>\n<p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u901a\u8fc7<code>&lt;util:list&gt;<\/code>\u6807\u7b7e\u5b9a\u4e49\u4e86\u4e00\u4e2a<code>ArrayList<\/code>\u7c7b\u578b\u7684\u96c6\u5408\uff0c\u5e76\u901a\u8fc7<code>&lt;property&gt;<\/code>\u6807\u7b7e\u5c06\u8fd9\u4e2a\u96c6\u5408\u6ce8\u5165\u5230<code>myList<\/code>\u5c5e\u6027\u4e2d\u3002<\/p>\n<p>\u65e0\u8bba\u4f7f\u7528\u54ea\u79cd\u65b9\u5f0f\uff0cSpring\u90fd\u4f1a\u8d1f\u8d23\u521b\u5efa\u96c6\u5408\u5bf9\u8c61\u5e76\u6ce8\u5165\u5230\u76f8\u5e94\u7684Bean\u4e2d\u3002\u9009\u62e9\u4f7f\u7528\u54ea\u79cd\u65b9\u5f0f\u53d6\u51b3\u4e8e\u4f60\u7684\u9879\u76ee\u914d\u7f6e\u548c\u4e2a\u4eba\u504f\u597d\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728Spring\u4e2d\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528@Autowired\u6ce8\u89e3\u6216\u8005\u901a\u8fc7XML\u914d\u7f6e\u6765\u6ce8\u5165Java\u96c6\u5408\u3002\u4ee5\u4e0b\u662f\u4e24\u79cd\u5e38\u89c1\u7684\u65b9\u5f0f [&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-12372","post","type-post","status-publish","format-standard","hentry","category-spring"],"_links":{"self":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/12372","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=12372"}],"version-history":[{"count":2,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/12372\/revisions"}],"predecessor-version":[{"id":47896,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/12372\/revisions\/47896"}],"wp:attachment":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/media?parent=12372"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/categories?post=12372"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/tags?post=12372"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}