{"id":291,"date":"2022-04-07T09:46:16","date_gmt":"2022-04-07T01:46:16","guid":{"rendered":"https:\/\/blog.lijiajia.top\/?p=291"},"modified":"2026-06-19T21:39:59","modified_gmt":"2026-06-19T13:39:59","slug":"spring%e6%a1%86%e6%9e%b6%e5%ad%a6%e4%b9%a0%ef%bc%9aioc%e6%93%8d%e4%bd%9cbean%e7%ae%a1%e7%90%86-%e5%bc%95%e5%85%a5%e5%a4%96%e9%83%a8%e5%b1%9e%e6%80%a7%e6%96%87%e4%bb%b6%e4%b9%9d","status":"publish","type":"post","link":"https:\/\/blog.ttwow.top\/?p=291","title":{"rendered":"Spring\u6846\u67b6\u5b66\u4e60\uff1aIOC\u64cd\u4f5cBean\u7ba1\u7406-\u5f15\u5165\u5916\u90e8\u5c5e\u6027\u6587\u4ef6(\u4e5d)"},"content":{"rendered":"<p>\u524d\u7f6e\uff1a\u5f15\u5165\u5fb7\u9c81\u4f0ajar\u5305-druid-1.1.9.jar<\/p>\n<h2>1.properties\u6587\u4ef6<\/h2>\n<pre><code class=\"language-markdown\">prop.DriverClass=com.mysql.jdbc.Driver\nprop.url=jdbc:mysql:\/\/localhsot:3307\/test\nprop.userName=root\nprop.passWord=root<\/code><\/pre>\n<h2>2.\u5f15\u5165context\u547d\u540d\u7a7a\u95f4<\/h2>\n<pre><code class=\"language-xml\">&lt;beans xmlns=&quot;http:\/\/www.springframework.org\/schema\/beans&quot;\n       xmlns:xsi=&quot;http:\/\/www.w3.org\/2001\/XMLSchema-instance&quot;\n       xmlns:p=&quot;http:\/\/www.springframework.org\/schema\/p&quot;\n       xmlns:util=&quot;http:\/\/www.springframework.org\/schema\/util&quot;\n       xmlns:context=&quot;http:\/\/www.springframework.org\/schema\/context&quot;\n       xsi:schemaLocation=&quot;http:\/\/www.springframework.org\/schema\/beans http:\/\/www.springframework.org\/schema\/beans\/spring-beans.xsd\n                           http:\/\/www.springframework.org\/schema\/util http:\/\/www.springframework.org\/schema\/util\/spring-util.xsd\n                           http:\/\/www.springframework.org\/schema\/context http:\/\/www.springframework.org\/schema\/context\/spring-context.xsd&quot;&gt;\n<\/code><\/pre>\n<h2>3.\u5f15\u5165\u914d\u7f6e\u6587\u4ef6\uff0c\u521b\u5efadataSource Bean\u5bf9\u8c61<\/h2>\n<pre><code class=\"language-xml\"> &lt;!--\u76f4\u63a5\u914d\u7f6e\u8fde\u63a5\u6c60--&gt;\n        &lt;bean id=&quot;dataSource&quot; class=&quot;com.alibaba.druid.pool.DruidDataSource&quot;&gt;\n            &lt;property name=&quot;driverClassName&quot; value=&quot;com.mysql.jdbc.Driver&quot;&gt;&lt;\/property&gt;\n            &lt;property name=&quot;url&quot; value=&quot;jdbc:mysql:\/\/localhost:3307:test&quot;&gt;&lt;\/property&gt;\n            &lt;property name=&quot;username&quot; value=&quot;root&quot;&gt;&lt;\/property&gt;\n            &lt;property name=&quot;password&quot; value=&quot;root&quot;&gt;&lt;\/property&gt;\n        &lt;\/bean&gt;\n\n        &lt;!--\u5f15\u5165\u5916\u90e8\u5c5e\u6027\u6587\u4ef6--&gt;\n        &lt;context:property-placeholder location=&quot;classpath:jdbc.properties&quot;&gt;&lt;\/context:property-placeholder&gt;\n        &lt;!--\u914d\u7f6e\u8fde\u63a5\u6c60--&gt;\n        &lt;bean id=&quot;dataSource&quot; class=&quot;com.alibaba.druid.pool.DruidDataSource&quot;&gt;\n            &lt;property name=&quot;driverClassName&quot; value=&quot;${prop.DriverClass}&quot;&gt;&lt;\/property&gt;\n            &lt;property name=&quot;url&quot; value=&quot;${prop.url}&quot;&gt;&lt;\/property&gt;\n            &lt;property name=&quot;username&quot; value=&quot;${prop.userName}&quot;&gt;&lt;\/property&gt;\n            &lt;property name=&quot;password&quot; value=&quot;${prop.passWord}&quot;&gt;&lt;\/property&gt;\n        &lt;\/bean&gt;\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u7f6e\uff1a\u5f15\u5165\u5fb7\u9c81\u4f0ajar\u5305-druid-1.1.9.jar 1.properties\u6587\u4ef6 prop.Driver [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[125],"tags":[68],"class_list":["post-291","post","type-post","status-publish","format-standard","hentry","category-java-backend","tag-spring"],"_links":{"self":[{"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=\/wp\/v2\/posts\/291","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=291"}],"version-history":[{"count":1,"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=\/wp\/v2\/posts\/291\/revisions"}],"predecessor-version":[{"id":2157,"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=\/wp\/v2\/posts\/291\/revisions\/2157"}],"wp:attachment":[{"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=291"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=291"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=291"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}