{"id":2571,"date":"2018-05-06T19:56:54","date_gmt":"2018-05-06T10:56:54","guid":{"rendered":"http:\/\/www.code-magagine.com\/?p=2571"},"modified":"2023-05-27T20:35:57","modified_gmt":"2023-05-27T11:35:57","slug":"%e3%80%90spring-framework%e3%80%91di%e3%82%92%e4%bd%93%e9%a8%93%e3%81%97%e3%81%a6%e3%81%bf%e3%82%8b%e3%80%82","status":"publish","type":"post","link":"http:\/\/www.code-magagine.com\/?p=2571","title":{"rendered":"\u3010Spring Framework\u3011DI(\u4f9d\u5b58\u6027\u306e\u6ce8\u5165)\u3092\u5b9f\u88c5\u3057\u3066\u307f\u308b\u3002(\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u304b\u3089\uff09"},"content":{"rendered":"<p>\u4e0b\u8a18\u306e\u8a18\u4e8b\u3067\u3001DI\u306f\u3001Spring Framework\u306e\u30b3\u30a2\u6a5f\u80fd\u3067\u3001\u91cd\u8981\u306a\u6a5f\u80fd\u3068\u3044\u3046\u3053\u3068\u3092\u3054\u7d39\u4ecb\u3055\u305b\u3066\u9802\u304d\u307e\u3057\u305f\u3002<\/p>\n<blockquote class=\"wp-embedded-content\" data-secret=\"2IiUBvrx0h\"><p><a href=\"http:\/\/www.code-magagine.com\/?p=2481\">\u3010Spring Framework\u3011Spring\u306e\u30b3\u30a2\u6a5f\u80fd(DI \uff1a\u4f9d\u5b58\u6027\u306e\u6ce8\u5165)\u306b\u3064\u3044\u3066<\/a><\/p><\/blockquote>\n<p><iframe class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; clip: rect(1px, 1px, 1px, 1px);\" src=\"http:\/\/www.code-magagine.com\/?p=2481&#038;embed=true#?secret=2IiUBvrx0h\" data-secret=\"2IiUBvrx0h\" width=\"500\" height=\"282\" title=\"&#8220;\u3010Spring Framework\u3011Spring\u306e\u30b3\u30a2\u6a5f\u80fd(DI \uff1a\u4f9d\u5b58\u6027\u306e\u6ce8\u5165)\u306b\u3064\u3044\u3066&#8221; &#8212; \u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u30de\u30ac\u30b8\u30f3\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe><\/p>\n<p>\u4eca\u56de\u306f\u3001DI\u306e\u5b9f\u88c5\u3092\u5b9f\u969b\u306b\u3084\u3063\u3066\u307f\u3066\u3001DI\u304c\u3069\u3093\u306a\u3082\u306e\u304b\u76f4\u611f\u7684\u306b\u7406\u89e3\u3092\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<h2>DI\u306e\u5b9f\u88c5<\/h2>\n<p>DI\u306e\u5b9f\u88c5\u306b\u306f\u3001\u300cBean\u300d\u3068\u3001\u300c\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u300d\u304c\u5fc5\u8981\u3068\u3054\u7d39\u4ecb\u3055\u305b\u3066\u9802\u304d\u307e\u3057\u305f\u3002<\/p>\n<h3>Bean\u306e\u6e96\u5099<\/h3>\n<p>\u307e\u305a\u306f\u3001Bean\u3092\u4f5c\u6210\u3057\u307e\u3057\u3087\u3046\u3002\u4f55\u3067\u3082\u3044\u3044\u3067\u3059\u304c\u3001\u4e0b\u8a18\u306e\u3088\u3046\u306b\u30b7\u30f3\u30d7\u30eb\u306a\u5f62\u3067Bean\u3092\u7528\u610f\u3057\u307e\u3057\u305f\u3002<\/p>\n<pre class=\"lang:default decode:true\">public class TestBean{\r\n\r\n\tprivate String helloworld; \r\n\r\n\tpublic String getHelloworld() {\r\n\t\treturn helloworld;\r\n\t}\r\n\r\n\tpublic void setHelloworld(String helloworld) {\r\n\t\tthis.helloworld = helloworld;\r\n\t}\r\n\r\n}<\/pre>\n<h3>\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u306e\u6e96\u5099<\/h3>\n<p>\u300csrc\/main\/resources\u300d\u3092\u53f3\u30af\u30ea\u30c3\u30af\u2192New\u2192\u300cSpring Bean Configuration File\u300d\u3092\u30af\u30ea\u30c3\u30af\u3057\u307e\u3059\u3002<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-2575\" src=\"http:\/\/www.code-magagine.com\/wp-content\/uploads\/2018\/05\/DI_\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb.png\" alt=\"\" width=\"570\" height=\"348\" srcset=\"http:\/\/www.code-magagine.com\/wp-content\/uploads\/2018\/05\/DI_\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb.png 570w, http:\/\/www.code-magagine.com\/wp-content\/uploads\/2018\/05\/DI_\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb-300x183.png 300w\" sizes=\"(max-width: 570px) 100vw, 570px\" \/><\/p>\n<p>\u3059\u308b\u3068\u4e0b\u8a18\u306e\u3088\u3046\u306a\u30d5\u30a1\u30a4\u30eb\u304c\u4f5c\u6210\u3055\u308c\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;\r\n&lt;beans xmlns=\"http:\/\/www.springframework.org\/schema\/beans\"\r\n\txmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\"\r\n\txsi:schemaLocation=\"http:\/\/www.springframework.org\/schema\/beans http:\/\/www.springframework.org\/schema\/beans\/spring-beans.xsd\"&gt;\r\n\r\n&lt;\/beans&gt;<\/pre>\n<p>\u30b5\u30f3\u30d7\u30eb\u306e\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u3068\u3057\u3066\u3001\u4e0b\u8a18\u3092\u5165\u529b\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;\r\n&lt;beans xmlns=\"http:\/\/www.springframework.org\/schema\/beans\"\r\n\txmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\"\r\n\txsi:schemaLocation=\"http:\/\/www.springframework.org\/schema\/beans http:\/\/www.springframework.org\/schema\/beans\/spring-beans.xsd\"&gt;\r\n\r\n\t&lt;bean id =\"beantest\" class=\"com.springapp.TestBean\"&gt;\r\n\t\t&lt;property name =\"helloworld\" value =\"Hello World!\" \/&gt;\r\n\t&lt;\/bean&gt;\r\n\r\n&lt;\/beans&gt;<\/pre>\n<p>\u66f8\u304d\u65b9\u3068\u3057\u3066\u306f\u3001\u4e0b\u8a18\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002Bean\u306b\u6ce8\u5165\u3059\u308b\u5024\u3092\u8a2d\u5b9a\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">&lt;bean id =\"\u540d\u524d\" class=\"\u30af\u30e9\u30b9\u540d\"&gt;\r\n\t&lt;property name =\"\u30d7\u30ed\u30d1\u30c6\u30a3\u540d\" value =\"\u6ce8\u5165\u3059\u308b\u5024\" \/&gt;\r\n&lt;\/bean&gt;<\/pre>\n<p>\u5b9f\u884c\u30d5\u30a1\u30a4\u30eb\u3068\u3057\u3066\u3001\u4e0b\u8a18\u3092\u7528\u610f\u3057\u307e\u3059\u3002<\/p>\n<p>\u4e0a\u8a18\u306e\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u3067\u3001id\u3068\u3057\u3066\u8a2d\u5b9a\u3057\u305f\u5024\u3092\u6307\u5b9a\u3059\u308c\u3070\u3001\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u304b\u3089\u5024\u3092\u53d6\u308a\u51fa\u3059\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">import org.springframework.context.ApplicationContext;\r\nimport org.springframework.context.support.ClassPathXmlApplicationContext;\r\n\r\npublic class Main {\r\n\r\n\tpublic static void main(String[] args) {\r\n\t\tApplicationContext app = new ClassPathXmlApplicationContext(\"bean.xml\");\r\n\t\tTestBean beantest = (TestBean)app.getBean(\"beantest\");\r\n\t\tSystem.out.println(beantest.getHelloworld());\r\n\t}\r\n\r\n}<\/pre>\n<h3>\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u7528\u610f\u3057\u305f\u5f8c\u306f\u3001\u4e0b\u8a18\u306e\u30a2\u30d7\u30ea\u69cb\u6210\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002<\/h3>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-2578\" src=\"http:\/\/www.code-magagine.com\/wp-content\/uploads\/2018\/05\/\u30d7\u30ed\u30b0\u30e9\u30e0\u69cb\u6210.png\" alt=\"\" width=\"242\" height=\"150\" \/><\/p>\n<h3>\u5b9f\u884c\u7d50\u679c<\/h3>\n<p>\u4e0b\u8a18\u306e\u3088\u3046\u306b\u3001\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u304b\u3089\u8aad\u307f\u8fbc\u307e\u308c\u305f\u6587\u5b57\u5217\u304c\u3001\u51fa\u529b\u3055\u308c\u3066\u3044\u308b\u3053\u3068\u304c\u308f\u304b\u308a\u307e\u3059\u3002<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-2576\" src=\"http:\/\/www.code-magagine.com\/wp-content\/uploads\/2018\/05\/\u5b9f\u884c\u7d50\u679c.png\" alt=\"\" width=\"285\" height=\"203\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"\u4e0b\u8a18\u306e\u8a18\u4e8b\u3067\u3001DI\u306f\u3001Spring Framework\u306e\u30b3\u30a2\u6a5f\u80fd\u3067\u3001\u91cd\u8981\u306a\u6a5f\u80fd\u3068\u3044\u3046\u3053\u3068\u3092\u3054\u7d39\u4ecb\u3055\u305b\u3066\u9802\u304d\u307e\u3057\u305f\u3002 \u3010Spring Framework\u3011Spring\u306e\u30b3\u30a2\u6a5f\u80fd(DI \uff1a\u4f9d\u5b58\u6027\u306e\u6ce8\u5165)\u306b\u3064\u3044\u3066 \u4eca\u56de\u306f\u3001DI [&hellip;]","protected":false},"author":1,"featured_media":2578,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[5],"tags":[],"_links":{"self":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/2571"}],"collection":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2571"}],"version-history":[{"count":9,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/2571\/revisions"}],"predecessor-version":[{"id":20231,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/2571\/revisions\/20231"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/media\/2578"}],"wp:attachment":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2571"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2571"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2571"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}