{"id":532,"date":"2023-03-23T21:19:42","date_gmt":"2023-03-23T13:19:42","guid":{"rendered":""},"modified":"2023-03-23T21:19:42","modified_gmt":"2023-03-23T13:19:42","slug":"spring \u521b\u5efa\u5e94\u7528","status":"publish","type":"post","link":"https:\/\/bianchenghao6.com\/532.html","title":{"rendered":"spring \u521b\u5efa\u5e94\u7528"},"content":{"rendered":"


\n <\/head>
\n <\/p>\n

\n

spring \u521b\u5efa\u5e94\u7528<\/h1>\n<\/p><\/div>\n
\n \u5728\u8fd9\u91cc\uff0c\u6211\u4eec\u5c06\u4f7f\u7528eclipse IDE\u521b\u5efa\u4e00\u4e2aspring\u6846\u67b6\u7684\u7b80\u5355\u5e94\u7528\u7a0b\u5e8f\u3002\u8ba9\u6211\u4eec\u770b\u770b\u5728Eclipse IDE\u4e2d\u521b\u5efaspring\u5e94\u7528\u7a0b\u5e8f\u7684\u7b80\u5355\u6b65\u9aa4\u3002\n <\/div>\n

\u521b\u5efaJava\u9879\u76ee<\/span>
\n \u6dfb\u52a0spring jar\u6587\u4ef6<\/span>
\n \u521b\u5efa\u7c7b<\/span>
\n \u521b\u5efaxml\u6587\u4ef6\u4ee5\u63d0\u4f9b\u503c<\/span>
\n \u521b\u5efa\u6d4b\u8bd5\u7c7b<\/span> <\/p>\n


\n

\u5728Eclipse IDE\u4e2d\u521b\u5efaspring\u5e94\u7528\u7a0b\u5e8f\u7684\u6b65\u9aa4<\/h2>\n
\n \u8ba9\u6211\u4eec\u770b\u4e00\u4e0b\u4f7f\u7528\u4ee5\u4e0b\u6b65\u9aa4\u521b\u5efa\u7b2c\u4e00\u4e2aspring\u5e94\u7528\u7a0b\u5e8f\u76845\u4e2a\u6b65\u9aa4: eclipse IDE\u3002\n <\/div>\n

1\u3001\u521b\u5efaJava\u9879\u76ee<\/h3>\n
\n \u8f6c\u5230
\n \u6587\u4ef6<\/strong>\u83dc\u5355-
\n \u65b0\u5efa<\/strong>-
\n \u9879\u76ee<\/strong>-
\n Java\u9879\u76ee<\/strong>\u3002\u8f93\u5165\u9879\u76ee\u540d\u79f0\uff0c\u4f8b\u5982firstspring-
\n \u5b8c\u6210<\/strong>\u3002\u73b0\u5728\uff0c\u521b\u5efa\u4e86Java\u9879\u76ee\u3002\n <\/div>\n

2\u3001\u6dfb\u52a0spring jar\u6587\u4ef6<\/h3>\n
\n \u8fd0\u884c\u8be5\u5e94\u7528\u7a0b\u5e8f\u4e3b\u8981\u9700\u8981\u4e09\u4e2ajar\u6587\u4ef6\u3002\n <\/div>\n

org.springframework.core-3.0.1.RELEASE-A <\/strong> <\/span>
\n com.springsource.org.apache.commons.logging-1.1.1 <\/strong> <\/span>
\n org.springframework.beans-3.0.1.RELEASE-A <\/strong> <\/span> <\/p>\n

\n \u4e3a\u4e86\u5c06\u6765\u4f7f\u7528\uff0c\u60a8\u53ef\u4ee5\u4e0b\u8f7dspring\u6838\u5fc3\u5e94\u7528\u7a0b\u5e8f\u6240\u9700\u7684jar\u6587\u4ef6\u3002\n <\/div>\n
\n \u4e0b\u8f7dSpring\u7684\u6838\u5fc3jar\u6587\u4ef6\n <\/div>\n
\n \u5168\u90e8\u4e0b\u8f7dSpring\u7684jar\u6587\u4ef6\uff0c\u5305\u62ecaop\uff0cmvc\uff0cj2ee\uff0cremoting\uff0coxm\u7b49\u3002\n <\/div>\n
\n \u8981\u8fd0\u884c\u6b64\u793a\u4f8b\uff0c\u60a8\u53ea\u9700\u52a0\u8f7dspring\u6838\u5fc3jar\u6587\u4ef6\u3002\n <\/div>\n
\n \u8981\u5728Eclipse IDE\u4e2d\u52a0\u8f7djar\u6587\u4ef6\uff0c
\n \u53f3\u952e\u5355\u51fb\u60a8\u7684\u9879\u76ee<\/strong>-
\n \u6784\u5efa\u8def\u5f84<\/strong>-
\n \u6dfb\u52a0\u5916\u90e8\u6863\u6848\u6587\u4ef6<\/strong>-
\n \u9009\u62e9\u6240\u6709\u5fc5\u9700\u7684\u6587\u4ef6jar\u6587\u4ef6<\/strong>-
\n \u5b8c\u6210\u3002<\/strong>\u3002\n <\/div>\n

3\u3001\u521b\u5efaJava\u7c7b<\/h3>\n
\n \u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u53ea\u662f\u5728\u521b\u5efa\u5177\u6709name\u5c5e\u6027\u7684Student\u7c7b\u3002\u5b66\u751f\u7684\u59d3\u540d\u5c06\u7531xml\u6587\u4ef6\u63d0\u4f9b\u3002\u8fd9\u53ea\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b\uff0c\u800c\u4e0d\u662fspring\u7684\u5b9e\u9645\u4f7f\u7528\u3002\u6211\u4eec\u5c06\u5728\"\u4f9d\u8d56\u6ce8\u5165\"\u4e00\u7ae0\u4e2d\u770b\u5230\u5b9e\u9645\u7684\u7528\u6cd5\u3002\u8981\u521b\u5efaJava\u7c7b\uff0c\u8bf7
\n \u53f3\u952e\u5355\u51fbsrc <\/strong>-
\n \u65b0\u5efa<\/strong>-
\n \u7c7b<\/strong>-
\n \u5199\u7c7b\u540d\u79f0\uff0c\u4f8b\u5982\u5b66\u751f<\/strong>-
\n \u5b8c\u6210<\/strong>\u3002\u7f16\u5199\u4ee5\u4e0b\u4ee3\u7801:\n <\/div>\n
\n
\npackage <\/span>com.lidihuo;\npublic <\/span>class <\/span>Student {\nprivate <\/span>String name;\npublic <\/span>String getName() {\n    return <\/span>name;\n}\npublic void <\/span>setName(String name) {\n    this<\/span>.name = name;\n}\npublic void <\/span>displayInfo(){\n    System.out.println<\/span>(\"Hello: \"<\/span>+name);\n}\n}\n<\/pre>\n

<\/code>\n <\/div>\n

\n \u8fd9\u662f\u7b80\u5355\u7684bean\u7c7b\uff0c\u4ec5\u5305\u542b\u4e00\u4e2a\u5e26\u6709\u5176getter\u548csetters\u65b9\u6cd5\u7684\u5c5e\u6027\u540d\u79f0\u3002\u6b64\u7c7b\u5305\u542b\u4e00\u4e2a\u540d\u4e3adisplayInfo()\u7684\u9644\u52a0\u65b9\u6cd5\uff0c\u8be5\u65b9\u6cd5\u901a\u8fc7\u95ee\u5019\u6d88\u606f\u6253\u5370\u5b66\u751f\u59d3\u540d\u3002\n <\/div>\n

4\u3001\u521b\u5efaxml\u6587\u4ef6<\/h3>\n
\n \u521b\u5efaxml\u6587\u4ef6\u5355\u51fbsrc-\u65b0\u5efa-file-\u7ed9\u51fa\u6587\u4ef6\u540d\uff0c\u4f8b\u5982applicationContext.xml-\u5b8c\u6210\u3002\u6253\u5f00applicationContext.xml\u6587\u4ef6\uff0c\u5e76\u7f16\u5199\u4ee5\u4e0b\u4ee3\u7801:\n <\/div>\n
\n
\n<?xml version=\"1.0\"<\/span> encoding=\"UTF-8\"<\/span>?>\n<beans\n    xmlns=\"http:\/\/www.springframework.org\/schema\/beans\"<\/span>\n    xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\"<\/span>\n    xmlns:p=\"http:\/\/www.springframework.org\/schema\/p\"<\/span>\n    xsi:schemaLocation=\"http:\/\/www.springframework.org\/schema\/beans\n               http:\/\/www.springframework.org\/schema\/beans\/spring-beans-3.0.xsd\">\n<bean id=\"studentbean\"<\/span> class=\"com.lidihuo.Student\"<\/span>>\n<property name=\"name\"<\/span> value=\"Vimal Jaiswal\"<\/span>><\/property>\n<\/bean>\n<\/beans>\n<\/pre>\n

<\/code>\n <\/div>\n

\n bean <\/strong>\u5143\u7d20\u7528\u4e8e\u4e3a\u7ed9\u5b9a\u7c7b\u5b9a\u4e49bean\u3002 bean\u7684
\n property <\/strong>\u5b50\u5143\u7d20\u6307\u5b9a\u540d\u4e3aname\u7684Student\u7c7b\u7684\u5c5e\u6027\u3002\u5c5e\u6027\u5143\u7d20\u4e2d\u6307\u5b9a\u7684\u503c\u5c06\u7531IOC\u5bb9\u5668\u5728Student\u7c7b\u5bf9\u8c61\u4e2d\u8bbe\u7f6e\u3002\n <\/div>\n

5\u3001\u521b\u5efa\u6d4b\u8bd5\u7c7b<\/h3>\n
\n \u521b\u5efaJava\u7c7b\uff0c\u4f8b\u5982\u6d4b\u8bd5\u3002\u5728\u8fd9\u91cc\uff0c\u6211\u4eec\u4f7f\u7528BeanFactory\u7684getBean()\u65b9\u6cd5\u4eceIOC\u5bb9\u5668\u4e2d\u83b7\u53d6Student\u7c7b\u7684\u5bf9\u8c61\u3002\u8ba9\u6211\u4eec\u770b\u4e00\u4e0b\u6d4b\u8bd5\u7c7b\u7684\u4ee3\u7801\u3002\n <\/div>\n
\n
\npackage <\/span>com.lidihuo;\nimport org.springframework.beans.factory.BeanFactory;\nimport org.springframework.beans.factory.xml.XmlBeanFactory;\nimport org.springframework.core.io.ClassPathResource;\nimport org.springframework.core.io.Resource;\npublic <\/span>class <\/span>Test {\npublic <\/span>static void <\/span>main(String[] args) {\n    Resource resource=new ClassPathResource(\"applicationContext.xml\"<\/span>);\n    BeanFactory factory=new XmlBeanFactory(resource);\n    \n    Student student=(Student)factory.getBean<\/span>(\"studentbean\"<\/span>);\n    student.displayInfo<\/span>();\n}\n}\n<\/pre>\n

<\/code>\n <\/div>\n

\n \u73b0\u5728\u8fd0\u884c\u6b64\u7c7b\u3002\u60a8\u5c06\u5f97\u5230\u8f93\u51faHello: Vimal Jaiswal\u3002\n <\/div>\n

spring \u521b\u5efa\u5e94\u7528_https:\/\/bianchenghao6.com_\u3010Spring \u6559\u7a0b\u3011_\u7b2c1\u5f20
\n <\/body>
\n<\/html><\/p>\n","protected":false},"excerpt":{"rendered":"spring \u521b\u5efa\u5e94\u7528zh-cn","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[105],"tags":[],"class_list":["post-532","post","type-post","status-publish","format-standard","hentry","category-bc_spring_jc"],"_links":{"self":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/posts\/532"}],"collection":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/comments?post=532"}],"version-history":[{"count":0,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/posts\/532\/revisions"}],"wp:attachment":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/media?parent=532"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/categories?post=532"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/tags?post=532"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}