{"id":10829,"date":"2023-04-20T08:54:54","date_gmt":"2023-04-20T00:54:54","guid":{"rendered":"http:\/\/123.57.164.21\/?p=10829"},"modified":"2023-04-20T09:01:45","modified_gmt":"2023-04-20T01:01:45","slug":"spring-batch-%e5%85%a5%e9%97%a8","status":"publish","type":"post","link":"https:\/\/92it.top\/?p=10829","title":{"rendered":"Spring batch \u5165\u95e8"},"content":{"rendered":"\n<p><strong>\u67b6\u6784\u8bbe\u8ba1\u53ca\u6982\u5ff5<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>\u51e0\u4e2a\u7cfb\u7edf\u9879\u76ee\u5927\u591a\u662fSpring\u67b6\u6784\uff0c\u6211\u5374\u4e00\u76f4\u5bf9Spring\u9c9c\u6709\u7814\u7a76\uff0c\u5b9e\u5728\u60ed\u6127\u3002\u516c\u53f8\u4e00\u4e2a\u6709\u5e74\u4ee3\u7684\u7cfb\u7edf\uff0c\u56e0\u4e3a\u5e94\u7528\u5404\u6a21\u5757\u6346\u5f97\u592a\u6df1\uff0c\u540e\u53f0\u6279\u5904\u7406\u65f6\u95f4\u5206\u5e03\u592a\u5bbd\uff0c\u6bcf\u6b21\u4e0d\u8bba\u66f4\u65b0\u54ea\u4e2a\u6a21\u5757\u529f\u80fd\u53d1\u5e03\u90fd\u5f97\u5361\u7740\u6279\u4efb\u52a1\u7684\u65f6\u95f4\u95f4\u9699\u5168\u505c\u5168\u8d77\u3002\u6253\u7b97\u7528Spring Batch\u91cd\u6784\u4e00\u4e0b\uff0c\u6b63\u597d\u5b66\u4e60\u4e00\u4e0bSpring\u4f53\u7cfb\u3002<\/p>\n\n\n\n<p>Spring Batch\u57fa\u672c\u8bbe\u8ba1\u6846\u67b6\u662f\u4e2a\u6837\u5b50\uff1a<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2023\/04\/image-258-1024x433.png\" alt=\"\" class=\"wp-image-10830\" width=\"480\" height=\"203\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-258-1024x433.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-258-300x127.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-258-768x325.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-258-830x351.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-258-230x97.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-258-350x148.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-258-480x203.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-258.png 1404w\" sizes=\"(max-width: 480px) 100vw, 480px\" \/><\/figure><\/div>\n\n\n\n<p>obLauncher\u6839\u636eJobParameters\u8bbe\u7f6e\u6765\u542f\u52a8Job\uff0cJob\u4f5c\u4e3aStep\u7684\u5bb9\u5668\uff0cJob\u9700\u8981\u5b9a\u4e49\u540d\u79f0\u3001Step\u987a\u5e8f\u548c\u662f\u5426\u652f\u6301\u91cd\u8dd1\u6807\u8bc6\u3002<\/p>\n\n\n\n<p>JobInstance\uff0c\u987e\u540d\u601d\u4e49\uff0c\u662fJob\u7684\u903b\u8f91\u5b9e\u4f8b\uff0c\u7531JobParameters\u6765\u63a7\u5236\u542f\u7528\uff08JobInstance=Job+\u7279\u5b9a\u7684JobParameters\uff09\u3002\u6240\u8c13\u903b\u8f91\u5c31\u8981\u5bf9\u5e94\u771f\u5b9e\u201c\u7269\u7406\u201d\u6267\u884c\uff0cJobExecution\u662f\u5bf9\u5e94\u7684\u6267\u884c\u5b9e\u4f8b\u3002\u4e00\u4e2aJobInstance\u6bcf\u6b21\u6267\u884c\u90fd\u5bf9\u5e94\u4e00\u4e2aJobExecution\uff0c\u5373\u5982\u679c\u591a\u6b21\u91cd\u590d\u6267\u884c\u4f1a\u6709\u591a\u4e2aJobExecution\u3002<\/p>\n\n\n\n<p>\u6bcf\u4e2aJob\u4e0b\u53ef\u80fd\u4f1a\u6709\u4e00\u4e2a\u6216\u591a\u4e2a\u7684Step\uff0cStep\u901a\u8fc7StepExecution\u542f\u52a8\u6267\u884c\u6b65\u9aa4\uff0cStepExecution\u4e0e\u5404\u81ea\u7684JobExecution\u76f8\u5bf9\u5e94\u3002Batch\u6846\u67b6\u8fd8\u9700\u8981\u5728\u6570\u636e\u5e93\u4e2d\u521b\u5efa\u4e00\u4e9b\u8868\uff08\u9ed8\u8ba4BATCH_*\u6253\u5934\uff09\u7528\u4e8e\u8bb0\u5f55\u6279\u4efb\u52a1\u6267\u884c\u4e2d\u7684\u72b6\u6001\u4fe1\u606f\uff0cJobRepository\u5219\u8d1f\u8d23\u7ba1\u7406\u8fd9\u4e9b\u8868\u6570\u636e\u6301\u4e45\u5316\u3002\u597d\u50cf\u662f\u6709\u70b9\u7ed5\uff0c\u4e2a\u4eba\u7406\u89e3\u4e3e\u4e2a\u4e0d\u6070\u5f53\u7684\u6817\u5b50\uff1a<\/p>\n\n\n\n<ul><li>Job\uff1a\u505a\u4e00\u7897\u7cbe\u81f4\u7684\u7ea2\u70e7\u725b\u8089\u9762<ul><li><em>Step_1\uff1a\u5148\u52a0\u6c34\u52a0\u9762\uff1bStep_2\uff1a\u518d\u7167\u65b9\u52a0\u6599\u76db\u9762<\/em><\/li><\/ul><\/li><li>JobParameters\uff1a\u5ba2\u4ebaA\u4e0b\u5355\u5566\uff0c\u5fae\u8fa3\u3001\u5c11\u8471<\/li><li>JobLauncher\uff1a\u4f20\u8bdd\u5c0f\u4e8c\uff0c\u544a\u8bc9\u540e\u53a8Parameters\u6765\u5566\uff0c\u5f00\u59cb\u5e72\u6d3b<\/li><li>JobInstance\uff1a\u7ed9\u540e\u53a8\u7684\u6e05\u5355\u2014\u2014\u7ed9\u5ba2\u6237A\u505a\u4e00\u7897\u7cbe\u81f4\u7684\uff0c\u5fae\u8fa3\u3001\u5c11\u8471\u7684\u725b\u8089\u9762<\/li><li>JobExecution_1\uff1a\u540e\u53a8\u771f\u7684\u7ed9\u5ba2\u6237A\u505a\u4e00\u7897\u7cbe\u81f4\u7684\uff0c\u5fae\u8fa3\u3001\u5c11\u8471\u7684\u725b\u8089\u9762<ul><li><em>StepExecution_1-1\uff1a\u5927\u53a8\u52a0\u6c34\u52a0\u9762\uff0c\u6325\u6c57\u5982\u96e8\uff1b<\/em><\/li><li><em>StepExecution_1-2\uff1a\u5e2e\u53a8\u5c0f\u5e08\u5085\u52a0\u6599\u6492\u76d0\uff0c\u53d6\u7897\u76db\u9762<\/em><\/li><\/ul><\/li><li>JobExecution_2\uff1a\u5ba2\u6237\u6295\u8bc9\u8471\u653e\u591a\u4e86\uff0c\u91cd\u505a\u4e00\u4efd\uff01\u5bf9\u5e94\u5355\u5b50\u8fd8\u662f\u4e4b\u524d\u7684JobInstance<ul><li><em>StepExecution_2-1\uff1a\u5927\u53a8\u52a0\u6c34\u52a0\u9762\uff0c\u6325\u6c57\u5982\u96e8\uff1b<\/em><\/li><li><em>StepExecution_2-2\uff1a\u5e2e\u53a8\u5c0f\u5e08\u5085\u52a0\u6599\u6492\u76d0\uff0c\u53d6\u7897\u76db\u9762<\/em><\/li><\/ul><\/li><li>JobRepository\uff1a\u628a\u4e0a\u9762\u7684\u83dc\u5355\u3001\u5ba2\u6237\u70b9\u5355\u6d41\u6c34\u3001\u6295\u8bc9\u5efa\u8bae\u5df4\u62c9\u5df4\u62c9\u90fd\u8bb0\u5230\u8d26\u7c3f\u91cc<\/li><\/ul>\n\n\n\n<p><strong>@EnableBatchProcessing \u4f5c\u7528<\/strong><\/p>\n\n\n\n<p>Spring\u91cc\u9762\u6709\u597d\u4e9b@Enable*\u7c7b\u7684\u6ce8\u89e3\uff0c\u4f5c\u7528\u5927\u81f4\u90fd\u662f\u81ea\u52a8\u6ce8\u518c\u6240\u63d0\u4f9b\u6a21\u5757\u529f\u80fd\u9700\u8981\u7684Bean\uff0c\u5f00\u7bb1\u5373\u7528\u3002\u5bf9\u4e8eSpring Batch\u800c\u8a00\uff0c\u76f8\u5173\u4f9d\u8d56\u5305\u5f15\u5165\u540e\uff0c\u914d\u7f6e@EnableBatchProcessiong\u4f1a\u81ea\u52a8\u6ce8\u518c\u4e0b\u8ff0Bean\uff1a<\/p>\n\n\n\n<ul><li>JobRepository\u3001JobLaunch\uff0c\u4f5c\u7528\u5982\u4e0a\u8ff0<\/li><li>JobRegistry\uff0c\u7528\u4e8e\u8ffd\u8e2a\u4e0a\u4e0b\u6587job\u4fe1\u606f\uff0c\u5305\u62ecApplicationContextFactory\u548cJobLoader<\/li><li>PlatformTransactionManager\uff0cSpring\u57fa\u7840\u4e0d\u597d\uff0c\u7814\u7a76\u4e86\u4e0b\uff0c\u8fd9\u4e2a\u7ee7\u627f\u81eaTransactionManager\u63a5\u53e3\uff0c\u7528\u4e8eSpring\u6570\u636e\u4e8b\u52a1\u7ba1\u7406\u3002<\/li><li>JobBuilderFactory\u3001StepBuilderFactory\uff0c\u8fd9\u4e2a\u6bd4\u8f83\u597d\u7406\u89e3\uff0c\u7528\u4e8e\u751f\u4ea7Job\u548cStep<\/li><\/ul>\n\n\n\n<p>\u7531\u6b64\uff0c\u53ef\u4ee5\u5f00\u59cb\u6109\u5feb\u7684\u88c5\u914d\u4e0a\u8ff0Bean\u7f16\u5199\u81ea\u5df1\u7684\u6279\u4efb\u52a1\u903b\u8f91\u4e86\u3002<\/p>\n\n\n\n<p><strong>Job\u7684\u542f\u52a8<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p><strong>1.\u4f7f\u7528CommandLineJobRunner\u901a\u8fc7\u547d\u4ee4\u884c\u542f\u52a8<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">bash$ java CommandLineJobRunner io.spring.EndOfDayJobConfiguration endOfDay schedule.date(date)=2007\/05\/05<\/pre>\n\n\n\n<p>\u9700\u8981\u4f20\u5165\u53c2\u6570\uff1ajobPath\uff0cjobName\u3002CommandLineJobRunner\u7c7b\u4e2d\u5305\u542b\u4e86main\u5165\u53e3\u51fd\u6570<\/p>\n\n\n\n<p>2. <strong>Web\u5bb9\u5668\u542f\u52a8<\/strong><\/p>\n\n\n\n<p>\u51c6\u5907\u91c7\u7528\u8fd9\u7c7b\u65b9\u5f0f\u3002\u901a\u8fc7HttpRequest\u63a7\u5236\u542f\u52a8\uff0c\u524d\u53f0\u53ef\u901a\u8fc7@RestController\u63d0\u4f9b\u8bbf\u95ee\u63a5\u53e3\u63a7\u5236JobLauncher\uff0c\u901a\u8fc7@Scheduled(cron = &#8220;5 * * * * ?&#8221;)\u8bbe\u7f6e\u4f20\u5165\u5b9a\u65f6\u53c2\u6570<\/p>\n\n\n\n<p>\u8fd9\u91cc\u4e00\u822c\u4f1a\u7528\u5230\u4e86JobLauncher.run()\u65b9\u6cd5\u5c06JobParameters\u548cJob\u7ed1\u5b9a\u3002<\/p>\n\n\n\n<p>JobParameters\u901a\u8fc7JobParametersBuilder\u6765\u751f\u6210\u5e76\u8bbe\u7f6e\u53c2\u6570\u3002<\/p>\n\n\n\n<p><strong>Job\u6267\u884c\u60c5\u51b5\u7ba1\u7406<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<ul><li>JobExplorer\u67e5\u770bjob\u72b6\u6001\uff0c\u5373\u4eceJobRepository\u8fdb\u884c\u8bfb\u53d6\u64cd\u4f5c<\/li><li>JobOperator\u7528\u4e8e\u505c\u6b62\u3001\u91cd\u8dd1\u7b49\u64cd\u4f5c\uff0c\u5373\u5bf9JobRepository\u5199\u64cd\u4f5c<\/li><\/ul>\n\n\n\n<p><strong>\u6ce8\u610f\u4e8b\u9879&amp;\u95ee\u9898<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>mark\u4e0b\u5199\u6848\u4f8b\u65f6\u9047\u5230\u7684\u95ee\u9898<\/p>\n\n\n\n<p><strong>\u5e38\u89c4\u914d\u7f6e<\/strong><\/p>\n\n\n\n<p>\u542f\u52a8\u65f6\u627e\u4e0d\u5230BATCH\u6570\u636e\u8868\u95ee\u9898\uff0c\u56e0\u4e3a\u521d\u59cb\u5316\u65f6\u9700\u8981\u521b\u5efa\u4e00\u4e9bBATCH_*\u6253\u5934\u7684\u6570\u636e\u8868\u7528\u4e8eJobRepository\u4fdd\u7559\u5143\u6570\u636e\uff0c\u89e3\u51b3\u4e5f\u5f88\u7b80\u5355\uff0c\u53ea\u9700\u5728properties\u6587\u4ef6\u4e2d\u52a0\u5165\u4e0b\u8ff0\u914d\u7f6e\u5373\u53ef<\/p>\n\n\n\n<p>\u7a0b\u5e8f\u542f\u52a8\u65f6\u4e0d\u5e0c\u671b\u81ea\u52a8\u6267\u884c\u4efb\u52a1\uff0c\u9700\u8981\u628a\u76f8\u5173\u914d\u7f6e\u7f6efalse<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># batch\nspring.batch.jdbc.initialize-schema=always\nspring.batch.job.enabled=false<\/pre>\n\n\n\n<p><strong>\u4f7f\u7528PostgreSQL\u6570\u636e\u5e93\u65f6\u6ca1\u6709public schema<\/strong><\/p>\n\n\n\n<p>\u6211\u81ea\u5df1\u751f\u6210\u5931\u8d25\u7684\u539f\u56e0\u3002<br>\u4e00\u4e2a\u5f88\u5f31\u667a\u7684\u539f\u56e0\u3002<br>\u6ca1\u6709\u521b\u5efa<code>public schema<\/code>\u3002\u5bfc\u81f4<a rel=\"noreferrer noopener\" href=\"https:\/\/so.csdn.net\/so\/search?q=%E5%85%83%E6%95%B0%E6%8D%AE&amp;spm=1001.2101.3001.7020\" target=\"_blank\">\u5143\u6570\u636e<\/a>\u8868\u751f\u6210\u65f6\u4e0d\u77e5\u9053\u5728\u54ea\u4e2aschema\u81ea\u52a8\u751f\u6210\u3002<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2023\/04\/image-259.png\" alt=\"\" class=\"wp-image-10833\" width=\"277\" height=\"143\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-259.png 512w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-259-300x155.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-259-230x119.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-259-350x180.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-259-480x248.png 480w\" sizes=\"(max-width: 277px) 100vw, 277px\" \/><\/figure><\/div>\n\n\n\n<p>\u5982\u679c\u6682\u65f6\u6ca1\u6709\u627e\u5230\u751f\u6210\u5931\u8d25\u7684\u539f\u56e0\uff0c\u53ef\u4ee5\u81ea\u884c\u4f7f\u7528sql\u811a\u672c\u6765\u521b\u5efa\u6570\u636e\u8868\u3002<br>\u8be5\u811a\u672c\u5b58\u5728\u4e8e<code>org.springframework.batch:spring-batch-core<\/code>\u4f9d\u8d56\u7684<code>spring-batch-core<\/code>\u5305\u4e2d<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2023\/04\/image-260-562x1024.png\" alt=\"\" class=\"wp-image-10834\" width=\"255\" height=\"465\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-260-562x1024.png 562w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-260-165x300.png 165w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-260-230x419.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-260-350x638.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-260-480x874.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2023\/04\/image-260.png 718w\" sizes=\"(max-width: 255px) 100vw, 255px\" \/><\/figure><\/div>\n\n\n\n<p>\u6709\u591a\u79cd\u4e0d\u540c\u6570\u636e\u5e93\u7684\u5143\u6570\u636e\u8868\u751f\u6210\u811a\u672c\u3002\u4e14\u5305\u542b\u5220\u9664\u811a\u672c\u3002\u5404\u4f4d\u4eb2\u81ea\u884c\u9009\u62e9\u5427\u3002<\/p>\n\n\n\n<p><strong>ORA-08177 \u65e0\u6cd5\u8fde\u7eed\u8bbf\u95ee\u6b64\u4e8b\u52a1\u5904\u7406\u95ee\u9898<\/strong><\/p>\n\n\n\n<p>\u8fd9\u4e2a\u95ee\u9898\u641e\u4e86\u6bd4\u8f83\u4e45\uff0c\u81ea\u5df1\u7535\u8111\u4e0a\u5efa\u6848\u4f8b\u7528MySql\u6570\u636e\u5e93\u65f6\u542f\u52a8\u5f88\u987a\u5229\u6ca1\u6709\u95ee\u9898\u3002\u800c\u540e\u5728\u516c\u53f8\u73af\u5883\u91cd\u6784\u6d4b\u8bd5\u65f6\uff0c\u4f7f\u7528Oracle\u6570\u636e\u5e93\u4f1a\u62a5<code>ORA-08177 \u65e0\u6cd5\u8fde\u7eed\u8bbf\u95ee\u6b64\u4e8b\u52a1\u5904\u7406\u95ee\u9898<\/code>\u9519\u8bef\u3002<\/p>\n\n\n\n<p>\u8fd9\u91cc\u6d89\u53ca\u5230\u6570\u636e\u5e93\u4e8b\u52a1\u7ba1\u7406\u7684\u8bbe\u7f6e\uff0c\u6570\u636e\u5e93\u4e8b\u52a1\u7ba1\u7406\u4e00\u822c\u53c8\u533a\u5206\u4e3a\u4f20\u64ad\u5c5e\u6027\uff08propagation\uff09\u548c\u4e8b\u52a1\u9694\u79bb\uff08isolation\uff09\u7ea7\u522b\u7684\u8bbe\u7f6e\u3002\u67e5\u4e86\u4e0b\u6b64\u95ee\u9898\u6309\u5b98\u65b9\u6587\u6863\u89e3\u91ca\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">The default isolation level for that method isSERIALIZABLE, which is quite aggressive.READ_COMMITTEDwould work just as well.READ_UNCOMMITTEDwould be fine if two processes are not likely to collide in this way.<\/pre>\n\n\n\n<p>\u5927\u6982\u610f\u601d\u662f\u9ed8\u8ba4\u9694\u79bb\u7ea7\u522b\u5b9a\u4e3a<code>SERIALIZABLE<\/code>\u592a\u4fdd\u5b88\u4e86\uff0c\u8bbe\u7f6e\u4e3a<code>READ_COMMITTED<\/code>\u5c31\u591f\u7528\u4e86\u3002\u7136\u540e\u5217\u51fa\u4e86\u4e24\u79cd\u8c03\u6574\u65b9\u5f0f\uff1a<\/p>\n\n\n\n<ol><li>\u91cd\u65b0\u751f\u6210JobRepository\u5b9e\u4f8b\uff0c\u5e76\u8bbe\u7f6e\u9694\u79bb\u7ea7\u522b\uff0c\u8986\u76d6\u9ed8\u8ba4\u7684Bean \u3002<\/li><li>\u901a\u8fc7\u52a8\u6001\u4ee3\u7406\u7c7b\u5b9e\u73b0\u5bf9JobRepository\u7684\u4e8b\u52a1\u7ea7\u522b\u76f8\u5173\u5c5e\u6027\u8bbe\u7f6e\uff0c\u6240\u8c13\u7684AOP<\/li><\/ol>\n\n\n\n<p>\u6709\u70b9\u56f0\u60d1\uff0c\u4e0d\u77e5\u9053\u4e3a\u5565\u4e0d\u80fd\u76f4\u63a5\u5728\u5df2\u6ce8\u518cJobRepository Bean\u4e2dset\u76f8\u5173\u5c5e\u6027\uff1f\u8981\u7ed5\u8fd9\u4e48\u4e00\u5708\u3002AOP\u65b9\u5f0f\u53c2\u8003\u4ee3\u7801\u5982\u4e0b\uff0c\u5b98\u65b9\u53c2\u8003\u6587\u6863\u91cc\u53ea\u8bbe\u7f6e\u4e86\u4f20\u64ad\u7ea7\u522b\uff0cOracle11\u4e0b\u6d4b\u8bd5\u4e0d\u884c\uff0c\u8fd8\u662f\u8981\u52a0\u4e0a\u9694\u79bb\u7ea7\u522b\u8c03\u6574\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">@Bean\npublic TransactionProxyFactoryBean baseProxy() {\n    TransactionProxyFactoryBean transactionProxyFactoryBean = new TransactionProxyFactoryBean();\n    Properties transactionAttributes = new Properties();\n    transactionAttributes.setProperty(\"*\", \"PROPAGATION_REQUIRED\"); \/\/ \u8bbe\u7f6e\u4f20\u64ad\u7ea7\u522b\n    transactionAttributes.setProperty(\"*\", \"ISOLATION_READ_COMMITTED\"); \/\/ \u8bbe\u7f6e\u9694\u79bb\u7ea7\u522b\n    transactionProxyFactoryBean.setTransactionAttributes(transactionAttributes);\n    transactionProxyFactoryBean.setTarget(jobRepository);\n    \/\/ TransactionProxyFactoryBean\u521b\u5efa\u4e8b\u52a1\u4ee3\u7406\u65f6\uff0c\u9700\u8981\u4e86\u89e3\u5f53\u524d\u4e8b\u52a1\u6240\u5904\u7684\u73af\u5883\uff0c\u8be5\u73af\u5883\u5c5e\u6027\u901a\u8fc7PlatformTransactionManager\u5b9e\u4f8b\uff08\u5176\u5b9e\u73b0\u7c7b\u7684\u5b9e\u4f8b\uff09\u4f20\u5165\n    transactionProxyFactoryBean.setTransactionManager(transactionManager);\n    return transactionProxyFactoryBean;\n}<\/pre>\n\n\n\n<p><strong>\u53c2\u6570\u4f20\u5165\u65f6\u673a\u95ee\u9898<\/strong><\/p>\n\n\n\n<p>\u8fd9\u662f\u56e0\u4e3aJob Bean\u5728\u5de5\u7a0b\u542f\u52a8\u65f6\u5c31\u521b\u5efa\u6ce8\u518c\u5230spring\u5bb9\u5668\uff0c\u800cJobParameter\u7684\u503c\u8fd8\u6ca1\u6709\u4ea7\u751f\u65e0\u6cd5\u83b7\u53d6\u3002<\/p>\n\n\n\n<p>\u8fd9\u91cc\u6d89\u53ca\u5230Spring\u53c8\u4e00\u4e2a\u91cd\u8981\u5185\u5bb9\u2014\u2014\u4f5c\u7528\u57df\u6ce8\u89e3<code>eg. @Scope(value=\"prototype\"<\/code>\u3002\u5bf9\u5e94\u5728Spring Batch\u4e2d\u6709\u4e13\u7528\u6ce8\u89e3<code>@StepScop<\/code>\u3002 \u5b83\u63d0\u4f9b\u4e00\u79cd\u540e\u7ed1\u5b9a\u6548\u679c\uff0c\u5c31\u662f\u5728\u751f\u6210Step\u7684\u65f6\u5019\u624d\u53bb\u521b\u5efabean\uff0c\u800c\u4e0d\u662f\u5728\u52a0\u8f7d\u914d\u7f6e\u4fe1\u606f\u7684\u65f6\u5019\u5c31\u521b\u5efa\u3002<\/p>\n\n\n\n<p>\u5177\u4f53\u8981\u914d\u5408<code>@Value(\"#{jobParameters[\u2018contractInfoDat\u2019]}\") <\/code>\u6ce8\u89e3\u4f7f\u7528\uff0c\u4ecejob\u7684\u542f\u52a8\u53c2\u6570\u4e2d\u83b7\u53d6\u6240\u9700\u53c2\u6570.<\/p>\n\n\n\n<p><strong>Job\u91cd\u590d\u6267\u884c\u95ee\u9898<\/strong><\/p>\n\n\n\n<p>\u6b63\u5e38\u6267\u884c\u4efb\u52a1\u60c5\u51b5\u4e0b\uff0c\u5982\u679c\u7528\u4e86<code>incrementer(new RunIdIncrementer())<\/code>\uff0c\u4f1a\u66f4\u65b0run.id\u53c2\u6570\u4f20\u5165\uff0c\u5bf9\u5e94\u5199\u5165\u6570\u636e\u8868\u4e2dBATCH_JOB<em>EXECUTION.JOB_INSTANCE_ID\u5b57\u6bb5\u3002<\/em><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Job: [FlowJob: [name=importUserJob]] launched with the following parameters: [{run.id=23}]<\/pre>\n\n\n\n<p>\u5982\u679c\u5b9a\u4e49\u4e86\u4e00\u4e2a\u7a7a\u7684JobParameter\uff0cjob_<em>instance_<\/em>id\u4e0d\u589e\u957f\u4ece\u800c\u5bfc\u81f4Job\u53ef\u80fd\u65e0\u6cd5\u91cd\u590d\u6267\u884c\uff0c\u7b80\u5355\u7684\u505a\u6cd5\u662f\u5c06\u5df2\u5b8c\u6210\u4efb\u52a1\u8bbe\u7f6e\u53ef\u91cd\u590d\u6267\u884c\uff0c\u901a\u8fc7\u5728step\u6267\u884c\u4e2d\u8c03\u7528allowStartIfComplete(true)\u65b9\u6cd5<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Job: [FlowJob: [name=importUserJob]] launched with the following parameters: [{}]\nStep already complete or not restartable, so no action to execute:<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u67b6\u6784\u8bbe\u8ba1\u53ca\u6982\u5ff5 \u51e0\u4e2a\u7cfb\u7edf\u9879\u76ee\u5927\u591a\u662fSpring\u67b6\u6784\uff0c\u6211\u5374\u4e00\u76f4\u5bf9Spring\u9c9c\u6709\u7814\u7a76\uff0c\u5b9e\u5728\u60ed\u6127\u3002\u516c\u53f8\u4e00\u4e2a\u6709\u5e74\u4ee3\u7684 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26,27],"tags":[],"_links":{"self":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/10829"}],"collection":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10829"}],"version-history":[{"count":2,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/10829\/revisions"}],"predecessor-version":[{"id":10835,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/10829\/revisions\/10835"}],"wp:attachment":[{"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10829"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10829"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10829"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}