{"id":531,"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 \u793a\u4f8b","status":"publish","type":"post","link":"https:\/\/bianchenghao6.com\/531.html","title":{"rendered":"Spring \u793a\u4f8b"},"content":{"rendered":"


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

\n

Spring \u793a\u4f8b<\/h1>\n<\/p><\/div>\n
\n \u5728\u8fd9\u91cc\uff0c\u6211\u4eec\u5c06\u5b66\u4e60\u521b\u5efa\u7b2c\u4e00\u4e2aspring\u5e94\u7528\u7a0b\u5e8f\u7684\u7b80\u5355\u6b65\u9aa4\u3002\u8981\u8fd0\u884c\u6b64\u5e94\u7528\u7a0b\u5e8f\uff0c\u6211\u4eec\u4e0d\u4f7f\u7528\u4efb\u4f55IDE\u3002\u6211\u4eec\u53ea\u662f\u5728\u4f7f\u7528\u547d\u4ee4\u63d0\u793a\u7b26\u3002\u8ba9\u6211\u4eec\u770b\u770b\u521b\u5efaspring\u5e94\u7528\u7a0b\u5e8f\u7684\u7b80\u5355\u6b65\u9aa4\n <\/div>\n

\u521b\u5efaJava\u7c7b<\/span>
\n \u521b\u5efaxml\u6587\u4ef6\u4ee5\u63d0\u4f9b\u503c<\/span>
\n \u521b\u5efa\u6d4b\u8bd5\u7c7b<\/span>
\n \u52a0\u8f7dspring jar\u6587\u4ef6<\/span>
\n \u8fd0\u884c\u6d4b\u8bd5\u7c7b<\/span> <\/p>\n


\n

\u521b\u5efaspring\u5e94\u7528\u7a0b\u5e8f\u7684\u6b65\u9aa4<\/h2>\n
\n \u8ba9\u6211\u4eec\u770b\u4e00\u4e0b\u521b\u5efa\u7b2c\u4e00\u4e2aspring\u76845\u4e2a\u6b65\u9aa4\n <\/div>\n

1)\u521b\u5efaJava\u7c7b<\/h3>\n
\n \u8fd9\u662f\u4ec5\u5305\u542bname\u5c5e\u6027\u7684\u7b80\u5355Java bean\u7c7b\u3002\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

2)\u521b\u5efaxml\u6587\u4ef6<\/h3>\n
\n \u5982\u679c\u4f7f\u7528myeclipse IDE\uff0c \uff0c\u60a8\u65e0\u9700\u521b\u5efaxml\u6587\u4ef6\uff0c\u56e0\u4e3amyeclipse\u53ef\u4ee5\u81ea\u5df1\u5b8c\u6210\u6b64\u64cd\u4f5c\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

3)\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 \u8d44\u6e90<\/strong>\u5bf9\u8c61\u8868\u793aapplicationContext.xml\u6587\u4ef6\u7684\u4fe1\u606f\u3002 Resource\u662f\u63a5\u53e3\uff0c\u800c
\n ClassPathResource <\/strong>\u662fReource\u63a5\u53e3\u7684\u5b9e\u73b0\u7c7b\u3002
\n BeanFactory <\/strong>\u8d1f\u8d23\u8fd4\u56deBean\u3002
\n XmlBeanFactory <\/strong>\u662fBeanFactory\u7684\u5b9e\u73b0\u7c7b\u3002 BeanFactory\u63a5\u53e3\u4e2d\u6709\u5f88\u591a\u65b9\u6cd5\u3002\u4e00\u79cd\u65b9\u6cd5\u662f
\n getBean()<\/strong>\uff0c\u8be5\u65b9\u6cd5\u8fd4\u56de\u5173\u8054\u7c7b\u7684\u5bf9\u8c61\u3002\n <\/div>\n

4)\u52a0\u8f7dspring\u6846\u67b6\u6240\u9700\u7684jar\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\u62eccore\uff0cweb\uff0caop\uff0cmvc\uff0cj2ee\uff0cremoting\uff0coxm\uff0cjdbc\uff0corm\u7b49\u3002\n <\/div>\n
\n \u8981\u8fd0\u884c\u6b64\u793a\u4f8b\uff0c\u60a8\u53ea\u9700\u8981\u52a0\u8f7dspring core jar\u6587\u4ef6\u3002\n <\/div>\n
\n

5)\u8fd0\u884c\u6d4b\u8bd5\u7c7b<\/h3>\n
\n \u73b0\u5728\u8fd0\u884cTest\u7c7b\u3002\u60a8\u5c06\u5f97\u5230\u8f93\u51faHello: Vimal Jaiswal\u3002\n <\/div>\n

Spring \u793a\u4f8b_https:\/\/bianchenghao6.com_\u3010Spring \u6559\u7a0b\u3011_\u7b2c1\u5f20
\n <\/body>
\n<\/html><\/p>\n","protected":false},"excerpt":{"rendered":"Spring \u793a\u4f8bzh-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-531","post","type-post","status-publish","format-standard","hentry","category-bc_spring_jc"],"_links":{"self":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/posts\/531"}],"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=531"}],"version-history":[{"count":0,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/posts\/531\/revisions"}],"wp:attachment":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/media?parent=531"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/categories?post=531"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/tags?post=531"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}