
{"id":2615,"date":"2020-12-08T11:37:02","date_gmt":"2020-12-08T03:37:02","guid":{"rendered":"http:\/\/127.0.0.2\/?p=2615"},"modified":"2020-12-08T11:38:39","modified_gmt":"2020-12-08T03:38:39","slug":"2020java%e6%a1%86%e6%9e%b6%e6%95%99%e7%a8%8b%e4%b9%8bspring%e6%a6%82%e8%bf%b0%e4%bb%a5%e5%8f%8a%e5%85%a5%e9%97%a8helloworld","status":"publish","type":"post","link":"https:\/\/www.9713job.com\/?p=2615","title":{"rendered":"2020java\u6846\u67b6\u6559\u7a0b\u4e4bspring\u6982\u8ff0\u4ee5\u53ca\u5165\u95e8helloworld"},"content":{"rendered":"<h3>2020java\u6846\u67b6\u6559\u7a0b\u4e4bspring\u6982\u8ff0\u4ee5\u53ca\u5165\u95e8helloworld<\/h3>\n<p><span style=\"color: #ff0000;\"><strong>\u4ec0\u4e48\u662fspring\uff1f<\/strong><\/span><\/p>\n<p>Spring\u662f\u4e00\u4e2a\u975e\u5e38\u6d3b\u8dc3\u7684\u5f00\u6e90\u6846\u67b6\uff0c\u7531Rod Johnson\u5f00\u53d1\uff0c\u5e2e\u52a9\u5206\u79bb\u9879\u76ee\u7ec4\u4ef6\u4e4b\u95f4\u7684\u4f9d\u8d56\u5173\u7cfb\uff0c\u5b83\u7684\u4e3b\u8981\u76ee\u7684\u662f\u7b80\u5316\u4f01\u4e1a\u5f00\u53d1<\/p>\n<p><span style=\"color: #ff0000;\"><strong>\u6838\u5fc3\u6982\u5ff5<\/strong><\/span><\/p>\n<p>IOC\uff1aInversion Of Control\u63a7\u5236\u53cd\u8f6c<\/p>\n<p>DI\uff1aDependency Injection \u4f9d\u8d56\u6ce8\u5165<\/p>\n<p>AOP\uff1aAspect Oriented Programming \u9762\u5411\u5207\u9762\u7f16\u7a0b<\/p>\n<p><span style=\"color: #ff0000;\"><strong>Spring\u7684\u7ec4\u6210<\/p>\n<p><\/strong><\/span><!--more--><\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-2254\" src=\"\/wp-content\/uploads\/2020\/12\/04\/90b5027b-4c50-4f58-b74a-b044b108a3eb.jpg\" alt=\"\" width=\"680\" \/><\/p>\n<p><strong>\u4f7f\u7528\u6ce8\u89e3\u914d\u7f6ebean\u5bf9\u8c61<\/strong><\/p>\n<pre>@Repository\r\npublic class MessageService {\r\n    public MessageService() {\r\n        System.out.println(\"MessageService...\");\r\n    }\r\n    \/\/\u6267\u884c\u6253\u5370\u529f\u80fd\uff0c\u8fd4\u56de\u8981\u6253\u5370\u7684\u5b57\u7b26\u4e32\r\n    public String getMessage(){\r\n        return \"Hello World\";\r\n    }\r\n}<\/pre>\n<p><strong>\u4f7f\u7528\u81ea\u52a8\u88c5\u914d<\/strong><\/p>\n<pre>@Repository\r\npublic class MessagePrinter {\r\n    public MessagePrinter() {\r\n        System.out.println(\"MessagePrinter...\");\r\n    }\r\n    \/\/\u5efa\u7acb\u548c MessageService\u7684\u5173\u7cfb\r\n    private MessageService ms;\r\n    \/\/\u8bbe\u7f6e ms \u7684\u503c\r\n    @Autowired\r\n    public void setMs(MessageService ms) {\r\n        this.ms = ms;\r\n    }\r\n    public void printMessage(){\r\n        System.out.println(this.ms.getMessage());\r\n    }\r\n}<\/pre>\n<p>\u4f7f\u7528\u6ce8\u89e3\u626b\u63cf<\/p>\n<pre>@ComponentScan\r\npublic class ApplicationSpring {\r\n    public static void main(String[] args) {\r\n        System.out.println(\"applicationSpring\");\r\n        ApplicationContext context;\r\n        \/\/\u521d\u59cb\u5316 spring \u5bb9\u5668\r\n        context=new AnnotationConfigApplicationContext(ApplicationSpring.class);\r\n        \/\/\u4ece\u5bb9\u5668\u83b7\u53d6 MessagePrinter \u5bf9\u8c61\r\n        MessagePrinter mp = context.getBean(MessagePrinter.class);\r\n        \/\/\u4ece\u5bb9\u5668\u83b7\u53d6 MessageService \u5bf9\u8c61\r\n        MessageService ms = context.getBean(MessageService.class);\r\n        System.out.println(ms.getMessage());\r\n    }\r\n}<\/pre>\n<p>\u4f7f\u7528XML\u6587\u4ef6\u914d\u7f6e<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-2254\" src=\"\/wp-content\/uploads\/2020\/12\/08\/1.png\" alt=\"\" width=\"680\" \/><\/p>\n<p>\u5229\u7528ClassPathXmlApplicationContext\u8bfb\u53d6\u914d\u7f6e\u6587\u4ef6<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-2254\" src=\"\/wp-content\/uploads\/2020\/12\/08\/2.png\" alt=\"\" width=\"680\" \/><\/p>\n<p>\u52a0\u8f7d\u914d\u7f6e\u6587\u4ef6<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-2254\" src=\"\/wp-content\/uploads\/2020\/12\/08\/3.png\" alt=\"\" width=\"680\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>2020java\u6846\u67b6\u6559\u7a0b\u4e4bspring\u6982\u8ff0\u4ee5\u53ca\u5165\u95e8helloworld \u4ec0\u4e48\u662fspring\uff1f Spring\u662f\u4e00 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-2615","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/posts\/2615","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.9713job.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2615"}],"version-history":[{"count":3,"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/posts\/2615\/revisions"}],"predecessor-version":[{"id":2618,"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/posts\/2615\/revisions\/2618"}],"wp:attachment":[{"href":"https:\/\/www.9713job.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2615"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.9713job.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2615"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.9713job.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2615"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}