<h2>名词说明:</h2> <p>上下文:</p> <p>执行:</p> <p>执行上下文:</p> <h2>案例:</h2> <p>警告:一旦steps共享数据,这些数据就会把这些steps连接起来。努力使steps独立。如果你实在是不能独立他们,才使用下面的技术。你应该把数据共享作为steps不能独立的后备方案。</p> <h2>1 数据共享方式:</h2> <ul> <li>a step存储共享数据到数据库,receiving step从数据库读取他们 </li> <li>Execution context(执行上下文): 使用Spring  Batch execution context 作为data容器。a step往上下文写数据,一个step从上下文读数据 </li> <li>Holder:使用Spring bean和依赖注入。Spring往communicating beans中注入一个holder bean。第一个step往holder中set values,另一个step从holder中reads values </li> </ul> <h2>2 使用execution context来共享数据</h2> <p>什么是execution context:ExecutionContext类就代表了执行上下文,它就是一个适合与批应用的 键值对的一个 map。下面就是一个从上下文读写数据的例子:</p> <blockquote> <pre><pre style="font-size: 12px; font-family: consolas,'Courier New',courier,monospace; width: 100%; margin: 0em; background-color: #ffffff">executionContext.putString("importId", importId); </pre><pre style="font-size: 12px; font-family: consolas,'Courier New',courier,monospace; width: 100%; margin: 0em; background-color: #ffffff&#
Spring Batch学习笔记——steps之间共享数据
最新推荐文章于 2023-01-17 22:45:00 发布