{"id":314,"date":"2022-04-08T22:59:48","date_gmt":"2022-04-08T14:59:48","guid":{"rendered":"https:\/\/blog.lijiajia.top\/?p=314"},"modified":"2026-06-19T21:51:46","modified_gmt":"2026-06-19T13:51:46","slug":"spring%e6%a1%86%e6%9e%b6%e5%ad%a6%e4%b9%a0%ef%bc%9a%e5%ae%8c%e5%85%a8%e6%b3%a8%e8%a7%a3%e4%ba%8b%e5%8a%a1%e7%ae%a1%e7%90%86%e4%ba%8c%e5%8d%81%e4%ba%8c","status":"publish","type":"post","link":"https:\/\/blog.ttwow.top\/?p=314","title":{"rendered":"Spring5\u6846\u67b6\u5b66\u4e60\uff1a\u5b8c\u5168\u6ce8\u89e3-\u58f0\u660e\u5f0f\u4e8b\u52a1\u7ba1\u7406(\u4e8c\u5341\u4e09)"},"content":{"rendered":"<h2>1.\u521b\u5efa\u914d\u7f6e\u7c7b\uff0c\u4f7f\u7528\u914d\u7f6e\u7c7b\u4ee3\u66ffxml\u914d\u7f6e\u6587\u4ef6<\/h2>\n<pre><code class=\"language-java\">@Configuration\/\/\u914d\u7f6e\u7c7b\n@ComponentScan(basePackages = {&quot;com.spring5&quot;})  \/\/\u7ec4\u4ef6\u626b\u63cf\n@EnableTransactionManagement    \/\/\u5f00\u542f\u4e8b\u52a1\npublic class TxConfig {\n\n    @Bean\n    public DruidDataSource getDruidDataSource(){\n        DruidDataSource dataSource = new DruidDataSource();\n        dataSource.setDriverClassName(&quot;com.mysql.jdbc.Driver&quot;);\n        dataSource.setUrl(&quot;jdbc:mysql:\/\/\/test&quot;);\n        dataSource.setUsername(&quot;root&quot;);\n        dataSource.setPassword(&quot;test&quot;);\n        return dataSource;\n    }\n\n    \/\/DataSource dataSource \u6839\u636e\u7c7b\u578b \u5230IOC\u5bb9\u5668\u4e2d \u627e\u5230\u5bf9\u8c61\n    @Bean\n    public JdbcTemplate getJdbcTemplate(DataSource dataSource){\n        JdbcTemplate jdbcTemplate = new JdbcTemplate();\n        \/\/\u6ce8\u5165dataSource\n        jdbcTemplate.setDataSource(dataSource);\n        return jdbcTemplate;\n    }\n\n    @Bean\n    public DataSourceTransactionManager getDataSourceTransactionManager(DataSource dataSource){\n\n        DataSourceTransactionManager dataSourceTransactionManager = new DataSourceTransactionManager();\n\n        dataSourceTransactionManager.setDataSource(dataSource);\n\n        return dataSourceTransactionManager;\n\n    }\n}\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>1.\u521b\u5efa\u914d\u7f6e\u7c7b\uff0c\u4f7f\u7528\u914d\u7f6e\u7c7b\u4ee3\u66ffxml\u914d\u7f6e\u6587\u4ef6 @Configuration\/\/\u914d\u7f6e\u7c7b @ComponentSc [&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,83],"class_list":["post-314","post","type-post","status-publish","format-standard","hentry","category-java-backend","tag-spring","tag-83"],"_links":{"self":[{"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=\/wp\/v2\/posts\/314","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=314"}],"version-history":[{"count":1,"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=\/wp\/v2\/posts\/314\/revisions"}],"predecessor-version":[{"id":2181,"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=\/wp\/v2\/posts\/314\/revisions\/2181"}],"wp:attachment":[{"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=314"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=314"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=314"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}