{"id":595,"date":"2023-10-22T08:39:10","date_gmt":"2023-05-11T04:55:06","guid":{"rendered":"https:\/\/www.silicloud.com\/ja\/blog\/index.php\/2023\/11\/30\/autowired%e3%82%a2%e3%83%8e%e3%83%86%e3%83%bc%e3%82%b7%e3%83%a7%e3%83%b3%e3%81%ae%e6%98%a5\/"},"modified":"2025-08-01T00:55:02","modified_gmt":"2025-07-31T15:55:02","slug":"autowired%e3%82%a2%e3%83%8e%e3%83%86%e3%83%bc%e3%82%b7%e3%83%a7%e3%83%b3%e3%81%ae%e6%98%a5","status":"publish","type":"post","link":"https:\/\/www.silicloud.com\/ja\/blog\/autowired%e3%82%a2%e3%83%8e%e3%83%86%e3%83%bc%e3%82%b7%e3%83%a7%e3%83%b3%e3%81%ae%e6%98%a5\/","title":{"rendered":"Autowired\u30a2\u30ce\u30c6\u30fc\u30b7\u30e7\u30f3\u306e\u6625"},"content":{"rendered":"<p>Spring\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u5185\u3067\u306f\u3001Spring @Autowired\u30a2\u30ce\u30c6\u30fc\u30b7\u30e7\u30f3\u3092\u4f7f\u7528\u3057\u3066\u81ea\u52d5\u7684\u306b\u4f9d\u5b58\u95a2\u4fc2\u306e\u6ce8\u5165\u304c\u884c\u308f\u308c\u307e\u3059\u3002Spring\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u306f\u4f9d\u5b58\u6027\u306e\u6ce8\u5165\u3092\u30d9\u30fc\u30b9\u306b\u69cb\u7bc9\u3055\u308c\u3066\u304a\u308a\u3001\u30af\u30e9\u30b9\u306e\u4f9d\u5b58\u95a2\u4fc2\u3092Spring Bean\u306e\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u3092\u4ecb\u3057\u3066\u6ce8\u5165\u3057\u307e\u3059\u3002<\/p>\n<h2>@Autowired\u30a2\u30ce\u30c6\u30fc\u30b7\u30e7\u30f3\u306e\u6625<\/h2>\n<p>\u901a\u5e38\u3001Spring\u306eBean\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u3067Bean\u306e\u8a2d\u5b9a\u8a73\u7d30\u3092\u63d0\u4f9b\u3057\u3001ref\u5c5e\u6027\u3092\u4f7f\u7528\u3057\u3066\u4ed6\u306eBean\u306b\u6ce8\u5165\u3059\u308bBean\u3082\u6307\u5b9a\u3057\u307e\u3059\u3002\u3057\u304b\u3057\u3001Spring\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u306f\u3001Bean\u306e\u6ce8\u5165\u8a73\u7d30\u3092\u660e\u793a\u7684\u306b\u63d0\u4f9b\u3059\u308b\u5fc5\u8981\u304c\u306a\u3044\u5834\u5408\u3067\u3082\u3001\u81ea\u52d5\u30ef\u30a4\u30e4\u30ea\u30f3\u30b0\u6a5f\u80fd\u3092\u63d0\u4f9b\u3057\u307e\u3059\u3002Spring\u306eBean\u3092\u81ea\u52d5\u30ef\u30a4\u30e4\u30ea\u30f3\u30b0\u3059\u308b\u65b9\u6cd5\u306f\u3044\u304f\u3064\u304b\u3042\u308a\u307e\u3059\u3002<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>autowire byName &#8211; \u3053\u306e\u30bf\u30a4\u30d7\u306e\u30aa\u30fc\u30c8\u30ef\u30a4\u30e4\u30ea\u30f3\u30b0\u3067\u306f\u3001\u4f9d\u5b58\u95a2\u4fc2\u306e\u30a4\u30f3\u30b8\u30a7\u30af\u30b7\u30e7\u30f3\u306b\u306f\u30bb\u30c3\u30bf\u30fc\u30e1\u30bd\u30c3\u30c9\u304c\u4f7f\u7528\u3055\u308c\u307e\u3059\u3002\u307e\u305f\u3001\u4f9d\u5b58\u95a2\u4fc2\u3092\u30a4\u30f3\u30b8\u30a7\u30af\u30b7\u30e7\u30f3\u3059\u308b\u30af\u30e9\u30b9\u3068Spring Bean\u306e\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u3067\u5909\u6570\u540d\u304c\u540c\u3058\u3067\u3042\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>autowire byType &#8211; \u3053\u306e\u30bf\u30a4\u30d7\u306e\u30aa\u30fc\u30c8\u30ef\u30a4\u30e4\u30ea\u30f3\u30b0\u3067\u306f\u3001\u30af\u30e9\u30b9\u306e\u30bf\u30a4\u30d7\u304c\u4f7f\u7528\u3055\u308c\u307e\u3059\u3002\u305d\u306e\u305f\u3081\u3001Spring Bean\u306e\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u306b\u306f\u3053\u306e\u30bf\u30a4\u30d7\u7528\u306b1\u3064\u3060\u3051\u306eBean\u304c\u8a2d\u5b9a\u3055\u308c\u3066\u3044\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>autowire by constructor &#8211; \u3053\u308c\u306f\u307b\u307cautowire byType\u3068\u540c\u3058\u3067\u3059\u304c\u3001\u9055\u3044\u306f\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\u304c\u4f9d\u5b58\u95a2\u4fc2\u306e\u30a4\u30f3\u30b8\u30a7\u30af\u30b7\u30e7\u30f3\u306b\u4f7f\u7528\u3055\u308c\u308b\u3053\u3068\u3067\u3059\u3002<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>autowire by autodetect &#8211; Spring 3.0\u4ee5\u524d\u306e\u30d0\u30fc\u30b8\u30e7\u30f3\u3092\u4f7f\u7528\u3057\u3066\u3044\u308b\u5834\u5408\u3001\u3053\u306e\u30aa\u30fc\u30c8\u30ef\u30a4\u30e4\u30ea\u30f3\u30b0\u306e\u30aa\u30d7\u30b7\u30e7\u30f3\u304c\u5229\u7528\u53ef\u80fd\u3067\u3059\u3002\u3053\u306e\u30aa\u30d7\u30b7\u30e7\u30f3\u306f\u3001Spring\u30b3\u30f3\u30c6\u30ca\u306b\u3088\u3063\u3066\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\u307e\u305f\u306fbyType\u306e\u30aa\u30fc\u30c8\u30ef\u30a4\u30e4\u30ea\u30f3\u30b0\u3068\u3057\u3066\u6c7a\u5b9a\u3055\u308c\u307e\u3057\u305f\u3002\u65e2\u306b\u591a\u304f\u306e\u30aa\u30d7\u30b7\u30e7\u30f3\u304c\u3042\u308b\u305f\u3081\u3001\u3053\u306e\u30aa\u30d7\u30b7\u30e7\u30f3\u306f\u975e\u63a8\u5968\u3068\u306a\u3063\u3066\u3044\u307e\u3059\u3002\u3053\u306e\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb\u3067\u306f\u3053\u306e\u30aa\u30d7\u30b7\u30e7\u30f3\u306f\u6271\u3044\u307e\u305b\u3093\u3002<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>@Autowired\u6ce8\u91c8 &#8211; Spring\u306e@Autowired\u6ce8\u91c8\u3092\u4f7f\u7528\u3057\u3066\u3001Spring Bean\u306e\u30aa\u30fc\u30c8\u30ef\u30a4\u30e4\u30ea\u30f3\u30b0\u3092\u884c\u3046\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002@Autowired\u6ce8\u91c8\u306f\u3001byType\u306e\u30aa\u30fc\u30c8\u30ef\u30a4\u30e4\u30ea\u30f3\u30b0\u306e\u305f\u3081\u306b\u5909\u6570\u3068\u30e1\u30bd\u30c3\u30c9\u306b\u9069\u7528\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u307e\u305f\u3001constructor\u3092\u4f7f\u7528\u3057\u305f\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\u30d9\u30fc\u30b9\u306eSpring\u306e\u30aa\u30fc\u30c8\u30ef\u30a4\u30e4\u30ea\u30f3\u30b0\u3067\u3082@Autowired\u6ce8\u91c8\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002@Autowired\u6ce8\u91c8\u3092\u4f7f\u7528\u3059\u308b\u306b\u306f\u3001Spring Bean\u306e\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u3067\u6ce8\u91c8\u30d9\u30fc\u30b9\u306e\u8a2d\u5b9a\u3092\u6709\u52b9\u306b\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u3053\u308c\u306f\u3001context:annotation-config\u8981\u7d20\u3092\u5b9a\u7fa9\u3059\u308b\u304b\u3001org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor\u578b\u306eBean\u3092\u5b9a\u7fa9\u3059\u308b\u3053\u3068\u3067\u884c\u3046\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol>@Qualifier\u6ce8\u91c8 &#8211; \u3053\u306e\u6ce8\u91c8\u306f\u3001Bean\u306e\u30de\u30c3\u30d4\u30f3\u30b0\u3067\u306e\u7af6\u5408\u3092\u56de\u907f\u3059\u308b\u305f\u3081\u306b\u4f7f\u7528\u3055\u308c\u3001\u30aa\u30fc\u30c8\u30ef\u30a4\u30e4\u30ea\u30f3\u30b0\u306b\u4f7f\u7528\u3059\u308bBean\u540d\u3092\u6307\u5b9a\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u3053\u306e\u3088\u3046\u306b\u3059\u308b\u3053\u3068\u3067\u3001\u540c\u3058\u30bf\u30a4\u30d7\u306e\u8907\u6570\u306eBean\u304c\u5b9a\u7fa9\u3055\u308c\u3066\u3044\u308b\u5834\u5408\u306e\u554f\u984c\u3092\u56de\u907f\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u3053\u306e\u6ce8\u91c8\u306f\u901a\u5e38\u3001@Autowired\u6ce8\u91c8\u3068\u4e00\u7dd2\u306b\u4f7f\u7528\u3055\u308c\u307e\u3059\u3002\u8907\u6570\u306e\u5f15\u6570\u3092\u6301\u3064\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\u306e\u5834\u5408\u3001\u3053\u306e\u6ce8\u91c8\u3092\u30e1\u30bd\u30c3\u30c9\u5185\u306e\u5f15\u6570\u540d\u3068\u3068\u3082\u306b\u4f7f\u7528\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/ol>\n<p>\u30c7\u30d5\u30a9\u30eb\u30c8\u3067\u306f\u3001Spring Bean\u306e\u81ea\u52d5\u30ef\u30a4\u30e4\u30ea\u30f3\u30b0\u306f\u7121\u52b9\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002Spring Bean\u306eautowire\u306e\u30c7\u30d5\u30a9\u30eb\u30c8\u5024\u306f\u300cdefault\u300d\u3067\u3042\u308a\u3001\u3053\u308c\u306f\u81ea\u52d5\u30ef\u30a4\u30e4\u30ea\u30f3\u30b0\u304c\u884c\u308f\u308c\u306a\u3044\u3053\u3068\u3092\u610f\u5473\u3057\u307e\u3059\u3002autowire\u5024\u300cno\u300d\u3082\u540c\u3058\u3088\u3046\u306a\u6319\u52d5\u3092\u793a\u3057\u307e\u3059\u3002Spring Bean\u306e\u81ea\u52d5\u30ef\u30a4\u30e4\u30ea\u30f3\u30b0\u306e\u4f7f\u7528\u4f8b\u3092\u793a\u3059\u305f\u3081\u306b\u3001\u30b7\u30f3\u30d7\u30eb\u306aSpring Maven\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3092\u4f5c\u6210\u3057\u307e\u3057\u3087\u3046\u3002\u6700\u7d42\u7684\u306a\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306f\u4ee5\u4e0b\u306e\u753b\u50cf\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002\u5404autowire\u30aa\u30d7\u30b7\u30e7\u30f3\u30921\u3064\u305a\u3064\u898b\u3066\u307f\u307e\u3057\u3087\u3046\u3002\u305d\u306e\u305f\u3081\u306b\u3001\u30e2\u30c7\u30eb\u306eBean\u3068\u30b5\u30fc\u30d3\u30b9\u30af\u30e9\u30b9\u3092\u4f5c\u6210\u3057\u3001\u30e2\u30c7\u30eb\u306eBean\u3092\u30a4\u30f3\u30b8\u30a7\u30af\u30b7\u30e7\u30f3\u3057\u307e\u3059\u3002<\/p>\n<h3>Spring\u306e@Autowired\u30a2\u30ce\u30c6\u30fc\u30b7\u30e7\u30f3\u3068\u306f\u3001Maven\u306e\u4f9d\u5b58\u95a2\u4fc2\u3067\u3059\u3002<\/h3>\n<p>\u6625\u306e\u81ea\u52d5\u30ef\u30a4\u30e4\u30ea\u30f3\u30b0\u306b\u306f\u3001\u8ffd\u52a0\u306e\u4f9d\u5b58\u95a2\u4fc2\u3092\u8ffd\u52a0\u3059\u308b\u5fc5\u8981\u306f\u3042\u308a\u307e\u305b\u3093\u3002\u79c1\u305f\u3061\u306epom.xml\u30d5\u30a1\u30a4\u30eb\u306b\u306f\u3001Spring\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u306e\u30b3\u30a2\u4f9d\u5b58\u95a2\u4fc2\u304c\u542b\u307e\u308c\u3066\u304a\u308a\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"post-pre\"><code>&lt;project xmlns=\"https:\/\/maven.apache.org\/POM\/4.0.0\" xmlns:xsi=\"https:\/\/www.w3.org\/2001\/XMLSchema-instance\"\r\n\txsi:schemaLocation=\"https:\/\/maven.apache.org\/POM\/4.0.0 https:\/\/maven.apache.org\/xsd\/maven-4.0.0.xsd\"&gt;\r\n\t&lt;modelVersion&gt;4.0.0&lt;\/modelVersion&gt;\r\n\t&lt;groupId&gt;org.springframework.samples&lt;\/groupId&gt;\r\n\t&lt;artifactId&gt;SpringBeanAutowiring&lt;\/artifactId&gt;\r\n\t&lt;version&gt;0.0.1-SNAPSHOT&lt;\/version&gt;\r\n\r\n\t&lt;properties&gt;\r\n\r\n\t\t&lt;!-- Generic properties --&gt;\r\n\t\t&lt;java.version&gt;1.6&lt;\/java.version&gt;\r\n\t\t&lt;project.build.sourceEncoding&gt;UTF-8&lt;\/project.build.sourceEncoding&gt;\r\n\t\t&lt;project.reporting.outputEncoding&gt;UTF-8&lt;\/project.reporting.outputEncoding&gt;\r\n\r\n\t\t&lt;!-- Spring --&gt;\r\n\t\t&lt;spring-framework.version&gt;4.0.2.RELEASE&lt;\/spring-framework.version&gt;\r\n\r\n\t\t&lt;!-- Logging --&gt;\r\n\t\t&lt;logback.version&gt;1.0.13&lt;\/logback.version&gt;\r\n\t\t&lt;slf4j.version&gt;1.7.5&lt;\/slf4j.version&gt;\r\n\r\n\t&lt;\/properties&gt;\r\n\r\n\t&lt;dependencies&gt;\r\n\t\t&lt;!-- Spring and Transactions --&gt;\r\n\t\t&lt;dependency&gt;\r\n\t\t\t&lt;groupId&gt;org.springframework&lt;\/groupId&gt;\r\n\t\t\t&lt;artifactId&gt;spring-context&lt;\/artifactId&gt;\r\n\t\t\t&lt;version&gt;${spring-framework.version}&lt;\/version&gt;\r\n\t\t&lt;\/dependency&gt;\r\n\t\t&lt;dependency&gt;\r\n\t\t\t&lt;groupId&gt;org.springframework&lt;\/groupId&gt;\r\n\t\t\t&lt;artifactId&gt;spring-tx&lt;\/artifactId&gt;\r\n\t\t\t&lt;version&gt;${spring-framework.version}&lt;\/version&gt;\r\n\t\t&lt;\/dependency&gt;\r\n\r\n\t\t&lt;!-- Logging with SLF4J &amp; LogBack --&gt;\r\n\t\t&lt;dependency&gt;\r\n\t\t\t&lt;groupId&gt;org.slf4j&lt;\/groupId&gt;\r\n\t\t\t&lt;artifactId&gt;slf4j-api&lt;\/artifactId&gt;\r\n\t\t\t&lt;version&gt;${slf4j.version}&lt;\/version&gt;\r\n\t\t\t&lt;scope&gt;compile&lt;\/scope&gt;\r\n\t\t&lt;\/dependency&gt;\r\n\t\t&lt;dependency&gt;\r\n\t\t\t&lt;groupId&gt;ch.qos.logback&lt;\/groupId&gt;\r\n\t\t\t&lt;artifactId&gt;logback-classic&lt;\/artifactId&gt;\r\n\t\t\t&lt;version&gt;${logback.version}&lt;\/version&gt;\r\n\t\t\t&lt;scope&gt;runtime&lt;\/scope&gt;\r\n\t\t&lt;\/dependency&gt;\r\n\r\n\t&lt;\/dependencies&gt;\r\n&lt;\/project&gt;\r\n<\/code><\/pre>\n<h3>\u30b9\u30d7\u30ea\u30f3\u30b0\u306e @Autowired \u30a2\u30ce\u30c6\u30fc\u30b7\u30e7\u30f3\u306b\u3088\u308b\u30e2\u30c7\u30eb\u30d3\u30fc\u30f3<\/h3>\n<p>\u7c21\u5358\u306aJava Bean\u3067\u3042\u308b\u300cEmployee\u300d\u3068\u3044\u3046\u540d\u524d\u306e\u30af\u30e9\u30b9\u3092\u4f5c\u308a\u307e\u3057\u3087\u3046\u3002\u3053\u306eBean\u306b\u306f\u3001\u30b2\u30c3\u30bf\u30fc\u3068\u30bb\u30c3\u30bf\u30fc\u304c\u3042\u308b\u30d7\u30ed\u30d1\u30c6\u30a3\u30921\u3064\u6301\u305f\u305b\u307e\u3059\u3002\u3053\u306e\u30d7\u30ed\u30d1\u30c6\u30a3\u306e\u5024\u306f\u3001Spring\u306eBean\u306e\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u3067\u521d\u671f\u5316\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"post-pre\"><code>package com.scdev.spring.autowiring.model;\r\n\r\npublic class Employee {\r\n\r\n\tprivate String name;\r\n\r\n\tpublic String getName() {\r\n\t\treturn name;\r\n\t}\r\n\r\n\tpublic void setName(String name) {\r\n\t\tthis.name = name;\r\n\t}\r\n}\r\n<\/code><\/pre>\n<h3>Spring\u306e@Autowired\u30a2\u30ce\u30c6\u30fc\u30b7\u30e7\u30f3 &#8211; \u30b5\u30fc\u30d3\u30b9\u30af\u30e9\u30b9<\/h3>\n<p>\u300cSpring\u306e\u81ea\u52d5\u30ef\u30a4\u30e4\u30ea\u30f3\u30b0\u3092\u901a\u3058\u3066\u3001Employee\u306ebean\u3092\u30a4\u30f3\u30b8\u30a7\u30af\u30c8\u3059\u308b\u30b5\u30fc\u30d3\u30b9\u30af\u30e9\u30b9\u3092\u4f5c\u6210\u3057\u307e\u3057\u3087\u3046\u3002\u300d<\/p>\n<pre class=\"post-pre\"><code>package com.scdev.spring.autowiring.service;\r\n\r\nimport com.scdev.spring.autowiring.model.Employee;\r\n\r\npublic class EmployeeService {\r\n\r\n\tprivate Employee employee;\r\n\r\n\t\/\/ constructor is used for autowire by constructor\r\n\tpublic EmployeeService(Employee emp) {\r\n\t\tSystem.out.println(\"Autowiring by constructor used\");\r\n\t\tthis.employee = emp;\r\n\t}\r\n\r\n\t\/\/ default constructor to avoid BeanInstantiationException for autowire\r\n\t\/\/ byName or byType\r\n\tpublic EmployeeService() {\r\n\t\tSystem.out.println(\"Default Constructor used\");\r\n\t}\r\n\r\n\t\/\/ used for autowire byName and byType\r\n\tpublic void setEmployee(Employee emp) {\r\n\t\tthis.employee = emp;\r\n\t}\r\n\r\n\tpublic Employee getEmployee() {\r\n\t\treturn this.employee;\r\n\t}\r\n}\r\n<\/code><\/pre>\n<p>\u79c1\u305f\u3061\u306f\u3001Spring\u306ebyName\u3001byType\u3001\u304a\u3088\u3073\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\u306b\u3088\u308b\u81ea\u52d5\u30ef\u30a4\u30e4\u30ea\u30f3\u30b0\u306b\u5bfe\u3057\u3066\u540c\u3058\u30b5\u30fc\u30d3\u30b9\u30af\u30e9\u30b9\u3092\u4f7f\u7528\u3057\u307e\u3059\u3002<br \/>\n\u30bb\u30c3\u30bf\u30fc\u30e1\u30bd\u30c3\u30c9\u306f\u3001byName\u3068byType\u306eSpring\u81ea\u52d5\u30ef\u30a4\u30e4\u30ea\u30f3\u30b0\u306b\u4f7f\u7528\u3055\u308c\u307e\u3059\u3002\u4e00\u65b9\u3001\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\u30d9\u30fc\u30b9\u306e\u30a4\u30f3\u30b8\u30a7\u30af\u30b7\u30e7\u30f3\u306f\u3001\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\u81ea\u52d5\u30ef\u30a4\u30e4\u30ea\u30f3\u30b0\u5c5e\u6027\u306b\u3088\u3063\u3066\u4f7f\u7528\u3055\u308c\u307e\u3059\u3002<br \/>\nSpring\u306ebyName\u307e\u305f\u306fbyType\u3092\u4f7f\u7528\u3059\u308b\u5834\u5408\u3001\u30c7\u30d5\u30a9\u30eb\u30c8\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\u304c\u4f7f\u7528\u3055\u308c\u307e\u3059\u3002\u305d\u306e\u305f\u3081\u3001\u79c1\u305f\u3061\u306fEmployeeService\u30d3\u30fc\u30f3\u306b\u660e\u793a\u7684\u306b\u30c7\u30d5\u30a9\u30eb\u30c8\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\u3092\u5b9a\u7fa9\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<h3>Spring\u306e@Autowired\u30a2\u30ce\u30c6\u30fc\u30b7\u30e7\u30f3\u306f\u3001byType\u306e\u81ea\u52d5\u30ef\u30a4\u30e4\u30ea\u30f3\u30b0\u306e\u4f8b\u3067\u3059\u3002<\/h3>\n<p>\u300cSpring\u306e@Autowired\u30a2\u30ce\u30c6\u30fc\u30b7\u30e7\u30f3\u3092\u4f7f\u7528\u3057\u3066\u3001autowiring byType\u306e\u305f\u3081\u306b\u5225\u306e\u30af\u30e9\u30b9\u3092\u4f5c\u6210\u3057\u307e\u3057\u3087\u3046\u3002\u300d<\/p>\n<pre class=\"post-pre\"><code>package com.scdev.spring.autowiring.service;\r\n\r\nimport org.springframework.beans.factory.annotation.Autowired;\r\n\r\nimport com.scdev.spring.autowiring.model.Employee;\r\n\r\npublic class EmployeeAutowiredByTypeService {\r\n\r\n\t\/\/Autowired annotation on variable\/setters is equivalent to autowire=\"byType\"\r\n\t@Autowired\r\n\tprivate Employee employee;\r\n\t\r\n\t@Autowired\r\n\tpublic void setEmployee(Employee emp){\r\n\t\tthis.employee=emp;\r\n\t}\r\n\t\r\n\tpublic Employee getEmployee(){\r\n\t\treturn this.employee;\r\n\t}\r\n}\r\n<\/code><\/pre>\n<p>\u6ce8\u610f\u3057\u3066\u304f\u3060\u3055\u3044\u3001Employee\u5909\u6570\u3068\u305d\u306e\u30bb\u30c3\u30bf\u30fc\u30e1\u30bd\u30c3\u30c9\u306e\u4e21\u65b9\u306b\u3001Spring\u306e@Autowired\u30a2\u30ce\u30c6\u30fc\u30b7\u30e7\u30f3\u3092\u4ed8\u3051\u307e\u3057\u305f\u304c\u3001\u3053\u308c\u3089\u306e\u3046\u3061\u306e\u3044\u305a\u308c\u304b1\u3064\u304cSpring Bean\u306e\u81ea\u52d5\u9023\u643a\u306b\u5341\u5206\u3067\u3059\u3002<\/p>\n<h3>Spring\u306e@Autowired\u30a2\u30ce\u30c6\u30fc\u30b7\u30e7\u30f3\u3068constructor\u306e\u4f8b\u3067\u306f\u3001@Qualifier\u30d3\u30fc\u30f3\u306e\u81ea\u52d5\u30ef\u30a4\u30e4\u30ea\u30f3\u30b0\u304c\u884c\u308f\u308c\u307e\u3059\u3002<\/h3>\n<p>\u5225\u306e\u30b5\u30fc\u30d3\u30b9\u30af\u30e9\u30b9\u3092\u4f5c\u6210\u3057\u307e\u3057\u3087\u3046\u3002\u3053\u3053\u3067\u306f\u3001\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\u30d9\u30fc\u30b9\u306e\u30a4\u30f3\u30b8\u30a7\u30af\u30b7\u30e7\u30f3\u306b@Autowired\u30a2\u30ce\u30c6\u30fc\u30b7\u30e7\u30f3\u3092\u4f7f\u7528\u3057\u307e\u3059\u3002\u307e\u305f\u3001@Qualifier\u30a2\u30ce\u30c6\u30fc\u30b7\u30e7\u30f3\u306e\u4f7f\u3044\u65b9\u3082\u78ba\u8a8d\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre class=\"post-pre\"><code>package com.scdev.spring.autowiring.service;\r\n\r\nimport org.springframework.beans.factory.annotation.Autowired;\r\nimport org.springframework.beans.factory.annotation.Qualifier;\r\n\r\nimport com.scdev.spring.autowiring.model.Employee;\r\n\r\npublic class EmployeeAutowiredByConstructorService {\r\n\r\n\tprivate Employee employee;\r\n\r\n\t\/\/Autowired annotation on Constructor is equivalent to autowire=\"constructor\"\r\n\t@Autowired(required=false)\r\n\tpublic EmployeeAutowiredByConstructorService(@Qualifier(\"employee\") Employee emp){\r\n\t\tthis.employee=emp;\r\n\t}\r\n\t\r\n\tpublic Employee getEmployee() {\r\n\t\treturn this.employee;\r\n\t}\r\n}\r\n<\/code><\/pre>\n<p>\u3053\u306e\u8c46\u304cSpring\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u306b\u3088\u3063\u3066\u521d\u671f\u5316\u3055\u308c\u308b\u3068\u3001\u540d\u524d\u304c\u300cemployee\u300d\u3068\u3044\u3046\u8c46\u304c\u81ea\u52d5\u30ef\u30a4\u30e4\u30ea\u30f3\u30b0\u306b\u4f7f\u7528\u3055\u308c\u307e\u3059\u3002Spring\u306e@Autowired\u30a2\u30ce\u30c6\u30fc\u30b7\u30e7\u30f3\u306f\u3001\u300crequired\u300d\u3068\u3044\u3046\u540d\u524d\u306e\u5f15\u6570\u3092\u53d7\u3051\u5165\u308c\u307e\u3059\u3002\u3053\u308c\u306f\u30c7\u30d5\u30a9\u30eb\u30c8\u5024\u304cTRUE\u306e\u30d6\u30fc\u30eb\u5024\u3067\u3059\u3002\u9069\u5207\u306a\u8c46\u304c\u81ea\u52d5\u30ef\u30a4\u30e4\u30ea\u30f3\u30b0\u7528\u306b\u898b\u3064\u304b\u3089\u306a\u3044\u5834\u5408\u306b\u3001Spring\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u304c\u4f8b\u5916\u3092\u30b9\u30ed\u30fc\u3057\u306a\u3044\u3088\u3046\u306b\u3001\u300cfalse\u300d\u306b\u5b9a\u7fa9\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<h3>\u30b9\u30d7\u30ea\u30f3\u30b0\u306e@Autowired\u30a2\u30ce\u30c6\u30fc\u30b7\u30e7\u30f3\u3068\u306f\u3001Bean\u306e\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u3067\u3059\u3002<\/h3>\n<p>\u30b9\u30d7\u30ea\u30f3\u30b0\u306e\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306b\u304a\u3044\u3066\u3001Spring Bean\u306e\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u306f\u4e3b\u8981\u306a\u90e8\u5206\u3067\u3059\u3002\u307e\u305a\u306f\u79c1\u305f\u3061\u306eSpring Bean\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u306e\u5916\u898b\u3092\u898b\u3066\u3001\u305d\u308c\u305e\u308c\u306e\u90e8\u5206\u3092\u8abf\u3079\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre class=\"post-pre\"><code>&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;\r\n&lt;beans xmlns=\"https:\/\/www.springframework.org\/schema\/beans\"\r\n\txmlns:xsi=\"https:\/\/www.w3.org\/2001\/XMLSchema-instance\"\r\n\txmlns:context=\"https:\/\/www.springframework.org\/schema\/context\"\r\n\txsi:schemaLocation=\"https:\/\/www.springframework.org\/schema\/beans https:\/\/www.springframework.org\/schema\/beans\/spring-beans.xsd\r\n\t\thttps:\/\/www.springframework.org\/schema\/context https:\/\/www.springframework.org\/schema\/context\/spring-context-4.0.xsd\"\r\n\t\t\r\n\t\tdefault-autowire=\"byName\" default-autowire-candidates=\"*\" &gt;\r\n\r\n&lt;bean name=\"employee\" class=\"com.scdev.spring.autowiring.model.Employee\"&gt;\r\n\t&lt;property name=\"name\" value=\"Pankaj\"&gt;&lt;\/property&gt;\r\n&lt;\/bean&gt;\r\n\r\n&lt;bean name=\"employee1\" class=\"com.scdev.spring.autowiring.model.Employee\" autowire-candidate=\"false\"&gt;\r\n\t&lt;property name=\"name\" value=\"Dummy Name\"&gt;&lt;\/property&gt;\r\n&lt;\/bean&gt;\r\n\r\n&lt;!-- autowiring byName, bean name should be same as the property name --&gt;\r\n&lt;bean name=\"employeeServiceByName\" class=\"com.scdev.spring.autowiring.service.EmployeeService\" autowire=\"byName\" \/&gt;\r\n\r\n&lt;!-- autowiring byType, there should be only one bean definition for the mapping --&gt;\r\n&lt;bean name=\"employeeServiceByType\" class=\"com.scdev.spring.autowiring.service.EmployeeService\" autowire=\"byType\" \/&gt;\r\n\r\n&lt;!-- autowiring by constructor --&gt;\r\n&lt;bean name=\"employeeServiceConstructor\" class=\"com.scdev.spring.autowiring.service.EmployeeService\" autowire=\"constructor\" \/&gt;\r\n\r\n&lt;!-- Enable Annotation based configuration --&gt;\r\n&lt;context:annotation-config \/&gt;\r\n\r\n&lt;!-- using @Autowiring annotation in below beans, byType and constructor --&gt;\r\n&lt;bean name=\"employeeAutowiredByTypeService\" class=\"com.scdev.spring.autowiring.service.EmployeeAutowiredByTypeService\" \/&gt;\r\n&lt;bean name=\"employeeAutowiredByConstructorService\" class=\"com.scdev.spring.autowiring.service.EmployeeAutowiredByConstructorService\" \/&gt;\r\n&lt;\/beans&gt;\r\n<\/code><\/pre>\n<p>Spring Bean\u306e\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u306b\u3064\u3044\u3066\u306e\u91cd\u8981\u306a\u30dd\u30a4\u30f3\u30c8\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u3067\u3059\u3002<\/p>\n<ul class=\"post-ul\">\n<li>beans element default-autowire is used to define the default autowiring method. Here I am defining the default autowiring method to be byName.<\/li>\n<li>beans element default-autowire-candidates is used to provide the pattern for bean names that can be used for autowiring. For simplicity I am allowing all the bean definitions to be eligible for autowiring, however if we can define some pattern for autowiring. For example, if we want only DAO bean definitions for autowiring, we can specify it as default-autowire-candidates=&#8221;*DAO&#8221;.<\/li>\n<li>autowire-candidate=&#8221;false&#8221; is used in a bean definition to make it ineligible for autowiring. It\u2019s useful when we have multiple bean definitions for a single type and we want some of them not to be autowired. For example, in above spring bean configurations \u201cemployee1\u201d bean will not be used for autowiring.<\/li>\n<li>autowire attribute byName, byType and constructor is self understood, nothing much to explain there.<\/li>\n<li>context:annotation-config is used to enable annotation based configuration support. Notice that employeeAutowiredByTypeService and employeeAutowiredByConstructorService beans don\u2019t have autowire attributes.<\/li>\n<\/ul>\n<h3>Spring\u306e@Autowired\u30a2\u30ce\u30c6\u30fc\u30b7\u30e7\u30f3 &#8211; \u30c6\u30b9\u30c8\u30d7\u30ed\u30b0\u30e9\u30e0<\/h3>\n<p>\u79c1\u305f\u3061\u306e\u6625\u306e\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306f\u3001\u3059\u3079\u3066\u306e\u30bf\u30a4\u30d7\u306e\u30b9\u30d7\u30ea\u30f3\u30b0\u30aa\u30fc\u30c8\u30ef\u30a4\u30e4\u30ea\u30f3\u30b0\u3092\u5099\u3048\u3066\u6e96\u5099\u304c\u3067\u304d\u307e\u3057\u305f\u306e\u3067\u3001\u4e88\u60f3\u901a\u308a\u306b\u6a5f\u80fd\u3059\u308b\u304b\u3069\u3046\u304b\u3092\u78ba\u8a8d\u3059\u308b\u305f\u3081\u306b\u3001\u7c21\u5358\u306a\u30c6\u30b9\u30c8\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u4f5c\u6210\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre class=\"post-pre\"><code>package com.scdev.spring.autowiring.main;\r\n\r\nimport org.springframework.context.support.ClassPathXmlApplicationContext;\r\n\r\nimport com.scdev.spring.autowiring.service.EmployeeAutowiredByConstructorService;\r\nimport com.scdev.spring.autowiring.service.EmployeeAutowiredByTypeService;\r\nimport com.scdev.spring.autowiring.service.EmployeeService;\r\n\r\npublic class SpringMain {\r\n\r\n\tpublic static void main(String[] args) {\r\n\t\tClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(\"spring.xml\");\r\n\t\t\r\n\t\tEmployeeService serviceByName = ctx.getBean(\"employeeServiceByName\", EmployeeService.class);\r\n\t\t\r\n\t\tSystem.out.println(\"Autowiring byName. Employee Name=\"+serviceByName.getEmployee().getName());\r\n\t\t\r\n\t\tEmployeeService serviceByType = ctx.getBean(\"employeeServiceByType\", EmployeeService.class);\r\n\t\t\r\n\t\tSystem.out.println(\"Autowiring byType. Employee Name=\"+serviceByType.getEmployee().getName());\r\n\t\t\r\n\t\tEmployeeService serviceByConstructor = ctx.getBean(\"employeeServiceConstructor\", EmployeeService.class);\r\n\t\t\r\n\t\tSystem.out.println(\"Autowiring by Constructor. Employee Name=\"+serviceByConstructor.getEmployee().getName());\r\n\t\t\r\n\t\t\/\/printing hashcode to confirm all the objects are of different type\r\n\t\tSystem.out.println(serviceByName.hashCode()+\"::\"+serviceByType.hashCode()+\"::\"+serviceByConstructor.hashCode());\r\n\t\t\r\n\t\t\/\/Testing @Autowired annotations\r\n\t\tEmployeeAutowiredByTypeService autowiredByTypeService = ctx.getBean(\"employeeAutowiredByTypeService\",EmployeeAutowiredByTypeService.class);\r\n\t\t\r\n\t\tSystem.out.println(\"@Autowired byType. Employee Name=\"+autowiredByTypeService.getEmployee().getName());\r\n\r\n\t\tEmployeeAutowiredByConstructorService autowiredByConstructorService = ctx.getBean(\"employeeAutowiredByConstructorService\",EmployeeAutowiredByConstructorService.class);\r\n\t\t\r\n\t\tSystem.out.println(\"@Autowired by Constructor. Employee Name=\"+autowiredByConstructorService.getEmployee().getName());\r\n\r\n\t\tctx.close();\r\n\t}\r\n}\r\n<\/code><\/pre>\n<p>\u30d7\u30ed\u30b0\u30e9\u30e0\u306f\u30b7\u30f3\u30d7\u30eb\u3067\u3059\u3002\u305f\u3060\u30b9\u30d7\u30ea\u30f3\u30b0\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u30b3\u30f3\u30c6\u30ad\u30b9\u30c8\u3092\u4f5c\u6210\u3057\u3001\u7570\u306a\u308b\u30d3\u30fc\u30f3\u3092\u53d6\u5f97\u3057\u3001\u5f93\u696d\u54e1\u306e\u540d\u524d\u3092\u8868\u793a\u3057\u3066\u3044\u307e\u3059\u3002\u4e0a\u8a18\u306e\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u5b9f\u884c\u3059\u308b\u3068\u3001\u4ee5\u4e0b\u306e\u51fa\u529b\u304c\u5f97\u3089\u308c\u307e\u3059\u3002<\/p>\n<pre class=\"post-pre\"><code>Mar 31, 2014 10:41:58 PM org.springframework.context.support.ClassPathXmlApplicationContext prepareRefresh\r\nINFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@3fa99295: startup date [Mon Mar 31 22:41:58 PDT 2014]; root of context hierarchy\r\nMar 31, 2014 10:41:58 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions\r\nINFO: Loading XML bean definitions from class path resource [spring.xml]\r\nDefault Constructor used\r\nDefault Constructor used\r\nAutowiring by constructor used\r\nAutowiring byName. Employee Name=Pankaj\r\nAutowiring byType. Employee Name=Pankaj\r\nAutowiring by Constructor. Employee Name=Pankaj\r\n21594592::15571401::1863015320\r\n@Autowired byType. Employee Name=Pankaj\r\n@Autowired by Constructor. Employee Name=Pankaj\r\nMar 31, 2014 10:41:58 PM org.springframework.context.support.ClassPathXmlApplicationContext doClose\r\nINFO: Closing org.springframework.context.support.ClassPathXmlApplicationContext@3fa99295: startup date [Mon Mar 31 22:41:58 PDT 2014]; root of context hierarchy\r\n<\/code><\/pre>\n<p>\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u3001autowire byName\u3068byType\u3067\u306f\u3001\u30c7\u30d5\u30a9\u30eb\u30c8\u306e\u5f15\u6570\u306a\u3057\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\u3092\u4f7f\u7528\u3057\u3066\u30d3\u30fc\u30f3\u3092\u521d\u671f\u5316\u3057\u3066\u3044\u307e\u3059\u3002autowire by constructor\u3067\u306f\u3001\u30d1\u30e9\u30e1\u30fc\u30bf\u30d9\u30fc\u30b9\u306e\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\u3092\u4f7f\u7528\u3057\u3066\u3044\u307e\u3059\u3002\u5168\u3066\u306e\u5909\u6570\u306e\u30cf\u30c3\u30b7\u30e5\u30b3\u30fc\u30c9\u304b\u3089\u3001\u5168\u3066\u306e\u30b9\u30d7\u30ea\u30f3\u30b0\u30d3\u30fc\u30f3\u304c\u7570\u306a\u308b\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3067\u3042\u308a\u3001\u540c\u3058\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u53c2\u7167\u3057\u3066\u3044\u306a\u3044\u3053\u3068\u3092\u78ba\u8a8d\u3057\u307e\u3057\u305f\u3002&#8221;employee1&#8243;\u3092autowiring\u306e\u5bfe\u8c61\u304b\u3089\u9664\u5916\u3057\u305f\u305f\u3081\u3001\u30d3\u30fc\u30f3\u306e\u30de\u30c3\u30d4\u30f3\u30b0\u306b\u6df7\u4e71\u306f\u3042\u308a\u307e\u305b\u3093\u3067\u3057\u305f\u3002\u3082\u3057&#8221;employee1&#8243;\u306e\u5b9a\u7fa9\u304b\u3089autowire-candidate=&#8221;false&#8221;\u3092\u524a\u9664\u3059\u308b\u3068\u3001\u4e0a\u8a18\u306emain\u30e1\u30bd\u30c3\u30c9\u3092\u5b9f\u884c\u3059\u308b\u969b\u306b\u4ee5\u4e0b\u306e\u30a8\u30e9\u30fc\u30e1\u30c3\u30bb\u30fc\u30b8\u304c\u8868\u793a\u3055\u308c\u307e\u3059\u3002<\/p>\n<pre class=\"post-pre\"><code>Exception in thread \"main\" org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'employeeServiceByType' defined in class path resource [spring.xml]: Unsatisfied dependency expressed through bean property 'employee': : No qualifying bean of type [com.scdev.spring.autowiring.model.Employee] is defined: expected single matching bean but found 2: employee,employee1; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [com.scdev.spring.autowiring.model.Employee] is defined: expected single matching bean but found 2: employee,employee1\r\n\tat org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireByType(AbstractAutowireCapableBeanFactory.java:1278)\r\n\tat org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1170)\r\n\tat org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)\r\n\tat org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)\r\n\tat org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)\r\n\tat org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)\r\n\tat org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)\r\n\tat org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)\r\n\tat org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:700)\r\n\tat org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760)\r\n\tat org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)\r\n\tat org.springframework.context.support.ClassPathXmlApplicationContext.&lt;init&gt;(ClassPathXmlApplicationContext.java:139)\r\n\tat org.springframework.context.support.ClassPathXmlApplicationContext.&lt;init&gt;(ClassPathXmlApplicationContext.java:83)\r\n\tat com.scdev.spring.autowiring.main.SpringMain.main(SpringMain.java:12)\r\nCaused by: org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [com.scdev.spring.autowiring.model.Employee] is defined: expected single matching bean but found 2: employee,employee1\r\n\tat org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:967)\r\n\tat org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:855)\r\n\tat org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireByType(AbstractAutowireCapableBeanFactory.java:1263)\r\n\t... 13 more\r\n<\/code><\/pre>\n<p>\u6625\u306e@Autowired\u30a2\u30ce\u30c6\u30fc\u30b7\u30e7\u30f3\u3068Spring\u306e\u81ea\u52d5\u914d\u7dda\u6a5f\u80fd\u306b\u3064\u3044\u3066\u306f\u4ee5\u4e0a\u3067\u3059\u3002\u4ee5\u4e0b\u306e\u30ea\u30f3\u30af\u304b\u3089\u30b5\u30f3\u30d7\u30eb\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3092\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3057\u3001\u3088\u308a\u8a73\u3057\u304f\u5b66\u3076\u305f\u3081\u306b\u5206\u6790\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<p>\u30b9\u30d7\u30ea\u30f3\u30b0\u30d3\u30fc\u30f3\u306e\u30aa\u30fc\u30c8\u30ef\u30a4\u30e4\u30ea\u30f3\u30b0\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3092\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Spring\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u5185\u3067\u306f\u3001Spring @Autowired\u30a2\u30ce\u30c6\u30fc\u30b7\u30e7\u30f3\u3092\u4f7f\u7528\u3057\u3066\u81ea\u52d5\u7684\u306b\u4f9d\u5b58\u95a2\u4fc2\u306e\u6ce8\u5165\u304c\u884c\u308f\u308c\u307e\u3059\u3002Spring\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u306f\u4f9d\u5b58\u6027\u306e\u6ce8\u5165\u3092\u30d9\u30fc\u30b9\u306b\u69cb\u7bc9\u3055\u308c\u3066\u304a\u308a\u3001\u30af\u30e9\u30b9\u306e\u4f9d\u5b58\u95a2\u4fc2\u3092Spri [&hellip;]<\/p>\n","protected":false},"author":8,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[26,61],"class_list":["post-595","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-26","tag-61"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v21.5 (Yoast SEO v21.5) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Autowired\u30a2\u30ce\u30c6\u30fc\u30b7\u30e7\u30f3\u306e\u6625 - Blog - Silicon Cloud<\/title>\n<meta name=\"description\" content=\"Autowired\u30a2\u30ce\u30c6\u30fc\u30b7\u30e7\u30f3\u306e\u6625\u3092\u5206\u304b\u308a\u3084\u3059\u304f\u89e3\u8aac\u3002\u5b9f\u8df5\u7684\u306a\u4f8b\u3068\u30b3\u30fc\u30c9\u3001\u6ce8\u610f\u70b9\u3092\u542b\u3081\u3066\u521d\u5fc3\u8005\u306b\u3082\u7406\u89e3\u3067\u304d\u308b\u3088\u3046\u8aac\u660e\u3057\u307e\u3059\u3002\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.silicloud.com\/ja\/blog\/autowired\u30a2\u30ce\u30c6\u30fc\u30b7\u30e7\u30f3\u306e\u6625\/\" \/>\n<meta property=\"og:locale\" content=\"ja_JP\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Autowired\u30a2\u30ce\u30c6\u30fc\u30b7\u30e7\u30f3\u306e\u6625\" \/>\n<meta property=\"og:description\" content=\"Autowired\u30a2\u30ce\u30c6\u30fc\u30b7\u30e7\u30f3\u306e\u6625\u3092\u5206\u304b\u308a\u3084\u3059\u304f\u89e3\u8aac\u3002\u5b9f\u8df5\u7684\u306a\u4f8b\u3068\u30b3\u30fc\u30c9\u3001\u6ce8\u610f\u70b9\u3092\u542b\u3081\u3066\u521d\u5fc3\u8005\u306b\u3082\u7406\u89e3\u3067\u304d\u308b\u3088\u3046\u8aac\u660e\u3057\u307e\u3059\u3002\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.silicloud.com\/ja\/blog\/autowired\u30a2\u30ce\u30c6\u30fc\u30b7\u30e7\u30f3\u306e\u6625\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog - Silicon Cloud\" \/>\n<meta property=\"article:published_time\" content=\"2023-05-11T04:55:06+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-07-31T15:55:02+00:00\" \/>\n<meta name=\"author\" content=\"\u84ee, \u7ffc\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u57f7\u7b46\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"\u84ee, \u7ffc\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u63a8\u5b9a\u8aad\u307f\u53d6\u308a\u6642\u9593\" \/>\n\t<meta name=\"twitter:data2\" content=\"40\u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.silicloud.com\/ja\/blog\/autowired%e3%82%a2%e3%83%8e%e3%83%86%e3%83%bc%e3%82%b7%e3%83%a7%e3%83%b3%e3%81%ae%e6%98%a5\/\",\"url\":\"https:\/\/www.silicloud.com\/ja\/blog\/autowired%e3%82%a2%e3%83%8e%e3%83%86%e3%83%bc%e3%82%b7%e3%83%a7%e3%83%b3%e3%81%ae%e6%98%a5\/\",\"name\":\"Autowired\u30a2\u30ce\u30c6\u30fc\u30b7\u30e7\u30f3\u306e\u6625 - Blog - Silicon Cloud\",\"isPartOf\":{\"@id\":\"https:\/\/www.silicloud.com\/ja\/blog\/#website\"},\"datePublished\":\"2023-05-11T04:55:06+00:00\",\"dateModified\":\"2025-07-31T15:55:02+00:00\",\"author\":{\"@id\":\"https:\/\/www.silicloud.com\/ja\/blog\/#\/schema\/person\/cdc124a0aaebf26393d8d591183ca413\"},\"description\":\"Autowired\u30a2\u30ce\u30c6\u30fc\u30b7\u30e7\u30f3\u306e\u6625\u3092\u5206\u304b\u308a\u3084\u3059\u304f\u89e3\u8aac\u3002\u5b9f\u8df5\u7684\u306a\u4f8b\u3068\u30b3\u30fc\u30c9\u3001\u6ce8\u610f\u70b9\u3092\u542b\u3081\u3066\u521d\u5fc3\u8005\u306b\u3082\u7406\u89e3\u3067\u304d\u308b\u3088\u3046\u8aac\u660e\u3057\u307e\u3059\u3002\",\"breadcrumb\":{\"@id\":\"https:\/\/www.silicloud.com\/ja\/blog\/autowired%e3%82%a2%e3%83%8e%e3%83%86%e3%83%bc%e3%82%b7%e3%83%a7%e3%83%b3%e3%81%ae%e6%98%a5\/#breadcrumb\"},\"inLanguage\":\"ja\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.silicloud.com\/ja\/blog\/autowired%e3%82%a2%e3%83%8e%e3%83%86%e3%83%bc%e3%82%b7%e3%83%a7%e3%83%b3%e3%81%ae%e6%98%a5\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.silicloud.com\/ja\/blog\/autowired%e3%82%a2%e3%83%8e%e3%83%86%e3%83%bc%e3%82%b7%e3%83%a7%e3%83%b3%e3%81%ae%e6%98%a5\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.silicloud.com\/ja\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Autowired\u30a2\u30ce\u30c6\u30fc\u30b7\u30e7\u30f3\u306e\u6625\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.silicloud.com\/ja\/blog\/#website\",\"url\":\"https:\/\/www.silicloud.com\/ja\/blog\/\",\"name\":\"Blog - Silicon Cloud\",\"description\":\"\",\"inLanguage\":\"ja\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.silicloud.com\/ja\/blog\/#\/schema\/person\/cdc124a0aaebf26393d8d591183ca413\",\"name\":\"\u84ee, \u7ffc\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ja\",\"@id\":\"https:\/\/www.silicloud.com\/ja\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/27308f733c7fcdac8617926a0100c77213339c4e501310a08c0baf946bf823bc?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/27308f733c7fcdac8617926a0100c77213339c4e501310a08c0baf946bf823bc?s=96&d=mm&r=g\",\"caption\":\"\u84ee, \u7ffc\"},\"url\":\"https:\/\/www.silicloud.com\/ja\/blog\/author\/rentsubasa\/\"},{\"@type\":\"ImageObject\",\"inLanguage\":\"ja\",\"@id\":\"https:\/\/www.silicloud.com\/ja\/blog\/autowired%e3%82%a2%e3%83%8e%e3%83%86%e3%83%bc%e3%82%b7%e3%83%a7%e3%83%b3%e3%81%ae%e6%98%a5\/#local-main-organization-logo\",\"url\":\"\",\"contentUrl\":\"\",\"caption\":\"Blog - Silicon Cloud\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Autowired\u30a2\u30ce\u30c6\u30fc\u30b7\u30e7\u30f3\u306e\u6625 - Blog - Silicon Cloud","description":"Autowired\u30a2\u30ce\u30c6\u30fc\u30b7\u30e7\u30f3\u306e\u6625\u3092\u5206\u304b\u308a\u3084\u3059\u304f\u89e3\u8aac\u3002\u5b9f\u8df5\u7684\u306a\u4f8b\u3068\u30b3\u30fc\u30c9\u3001\u6ce8\u610f\u70b9\u3092\u542b\u3081\u3066\u521d\u5fc3\u8005\u306b\u3082\u7406\u89e3\u3067\u304d\u308b\u3088\u3046\u8aac\u660e\u3057\u307e\u3059\u3002","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.silicloud.com\/ja\/blog\/autowired\u30a2\u30ce\u30c6\u30fc\u30b7\u30e7\u30f3\u306e\u6625\/","og_locale":"ja_JP","og_type":"article","og_title":"Autowired\u30a2\u30ce\u30c6\u30fc\u30b7\u30e7\u30f3\u306e\u6625","og_description":"Autowired\u30a2\u30ce\u30c6\u30fc\u30b7\u30e7\u30f3\u306e\u6625\u3092\u5206\u304b\u308a\u3084\u3059\u304f\u89e3\u8aac\u3002\u5b9f\u8df5\u7684\u306a\u4f8b\u3068\u30b3\u30fc\u30c9\u3001\u6ce8\u610f\u70b9\u3092\u542b\u3081\u3066\u521d\u5fc3\u8005\u306b\u3082\u7406\u89e3\u3067\u304d\u308b\u3088\u3046\u8aac\u660e\u3057\u307e\u3059\u3002","og_url":"https:\/\/www.silicloud.com\/ja\/blog\/autowired\u30a2\u30ce\u30c6\u30fc\u30b7\u30e7\u30f3\u306e\u6625\/","og_site_name":"Blog - Silicon Cloud","article_published_time":"2023-05-11T04:55:06+00:00","article_modified_time":"2025-07-31T15:55:02+00:00","author":"\u84ee, \u7ffc","twitter_card":"summary_large_image","twitter_misc":{"\u57f7\u7b46\u8005":"\u84ee, \u7ffc","\u63a8\u5b9a\u8aad\u307f\u53d6\u308a\u6642\u9593":"40\u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.silicloud.com\/ja\/blog\/autowired%e3%82%a2%e3%83%8e%e3%83%86%e3%83%bc%e3%82%b7%e3%83%a7%e3%83%b3%e3%81%ae%e6%98%a5\/","url":"https:\/\/www.silicloud.com\/ja\/blog\/autowired%e3%82%a2%e3%83%8e%e3%83%86%e3%83%bc%e3%82%b7%e3%83%a7%e3%83%b3%e3%81%ae%e6%98%a5\/","name":"Autowired\u30a2\u30ce\u30c6\u30fc\u30b7\u30e7\u30f3\u306e\u6625 - Blog - Silicon Cloud","isPartOf":{"@id":"https:\/\/www.silicloud.com\/ja\/blog\/#website"},"datePublished":"2023-05-11T04:55:06+00:00","dateModified":"2025-07-31T15:55:02+00:00","author":{"@id":"https:\/\/www.silicloud.com\/ja\/blog\/#\/schema\/person\/cdc124a0aaebf26393d8d591183ca413"},"description":"Autowired\u30a2\u30ce\u30c6\u30fc\u30b7\u30e7\u30f3\u306e\u6625\u3092\u5206\u304b\u308a\u3084\u3059\u304f\u89e3\u8aac\u3002\u5b9f\u8df5\u7684\u306a\u4f8b\u3068\u30b3\u30fc\u30c9\u3001\u6ce8\u610f\u70b9\u3092\u542b\u3081\u3066\u521d\u5fc3\u8005\u306b\u3082\u7406\u89e3\u3067\u304d\u308b\u3088\u3046\u8aac\u660e\u3057\u307e\u3059\u3002","breadcrumb":{"@id":"https:\/\/www.silicloud.com\/ja\/blog\/autowired%e3%82%a2%e3%83%8e%e3%83%86%e3%83%bc%e3%82%b7%e3%83%a7%e3%83%b3%e3%81%ae%e6%98%a5\/#breadcrumb"},"inLanguage":"ja","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.silicloud.com\/ja\/blog\/autowired%e3%82%a2%e3%83%8e%e3%83%86%e3%83%bc%e3%82%b7%e3%83%a7%e3%83%b3%e3%81%ae%e6%98%a5\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.silicloud.com\/ja\/blog\/autowired%e3%82%a2%e3%83%8e%e3%83%86%e3%83%bc%e3%82%b7%e3%83%a7%e3%83%b3%e3%81%ae%e6%98%a5\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.silicloud.com\/ja\/blog\/"},{"@type":"ListItem","position":2,"name":"Autowired\u30a2\u30ce\u30c6\u30fc\u30b7\u30e7\u30f3\u306e\u6625"}]},{"@type":"WebSite","@id":"https:\/\/www.silicloud.com\/ja\/blog\/#website","url":"https:\/\/www.silicloud.com\/ja\/blog\/","name":"Blog - Silicon Cloud","description":"","inLanguage":"ja"},{"@type":"Person","@id":"https:\/\/www.silicloud.com\/ja\/blog\/#\/schema\/person\/cdc124a0aaebf26393d8d591183ca413","name":"\u84ee, \u7ffc","image":{"@type":"ImageObject","inLanguage":"ja","@id":"https:\/\/www.silicloud.com\/ja\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/27308f733c7fcdac8617926a0100c77213339c4e501310a08c0baf946bf823bc?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/27308f733c7fcdac8617926a0100c77213339c4e501310a08c0baf946bf823bc?s=96&d=mm&r=g","caption":"\u84ee, \u7ffc"},"url":"https:\/\/www.silicloud.com\/ja\/blog\/author\/rentsubasa\/"},{"@type":"ImageObject","inLanguage":"ja","@id":"https:\/\/www.silicloud.com\/ja\/blog\/autowired%e3%82%a2%e3%83%8e%e3%83%86%e3%83%bc%e3%82%b7%e3%83%a7%e3%83%b3%e3%81%ae%e6%98%a5\/#local-main-organization-logo","url":"","contentUrl":"","caption":"Blog - Silicon Cloud"}]}},"_links":{"self":[{"href":"https:\/\/www.silicloud.com\/ja\/blog\/wp-json\/wp\/v2\/posts\/595","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.silicloud.com\/ja\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.silicloud.com\/ja\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/ja\/blog\/wp-json\/wp\/v2\/users\/8"}],"replies":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/ja\/blog\/wp-json\/wp\/v2\/comments?post=595"}],"version-history":[{"count":1,"href":"https:\/\/www.silicloud.com\/ja\/blog\/wp-json\/wp\/v2\/posts\/595\/revisions"}],"predecessor-version":[{"id":42592,"href":"https:\/\/www.silicloud.com\/ja\/blog\/wp-json\/wp\/v2\/posts\/595\/revisions\/42592"}],"wp:attachment":[{"href":"https:\/\/www.silicloud.com\/ja\/blog\/wp-json\/wp\/v2\/media?parent=595"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.silicloud.com\/ja\/blog\/wp-json\/wp\/v2\/categories?post=595"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.silicloud.com\/ja\/blog\/wp-json\/wp\/v2\/tags?post=595"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}