spring-cloud-task(1)简单使用

Spring Cloud Task使用关系数据库来存储执行任务的结果。 虽然可以在没有数据库的情况下开始开发任务(任务的状态会记录为任务存储库更新的一部分),但对于生产环境,您将需要使用受支持的数据库。 以下是目前支持的列表:

  • DB2
  • H2
  • HSQLDB
  • MySql
  • Oracle
  • Postgres
  • SqlServer
注解@EnableTask 告诉Spring Cloud Task引导它的功能。这是通过默认导入其他配置类SimpleTaskConfiguration来实现的。这个额外的配置注册了TaskRepository及其使用的基础设施。
TaskRepository将使用内存Map来记录任务的结果。显然这对于​​生产环境来说不是一个实际的解决方案,因为一旦任务结束,Map就会消失。但是,对于快速入门体验,我们使用这个作为默认值,并向日志回应该存储库中正在更新的内容。
TaskLifecyceListener将记录任务的开始和任务的结束。

在debug日志中:

2018-01**SimpleTaskRepository   : Creating: TaskExecution{executionId=0, parentExecutionId=null, exitCode=null, taskName='helloWorld', startTime=Sat Jan 06 00:18:44 CST 2018, endTime=null, exitMessage='null', externalExecutionId='null', errorMessage='null', arguments=[]}
Hello World!
2018-01-**SimpleTaskRepository   : Updating: TaskExecution with executionId=0 with the following {exitCode=0, endTime=Sat Jan 06 00:18:44 CST 2018, exitMessage='null', errorMessage='null'}
SimpleTaskRepository 创建了TaskRepository。
执行结束后
SimpleTaskRepository记录TaskRepository中任务的完成情况。

测试用例:

@RunWith(SpringRunner.class)
@SpringBootTest
@TestPropertySource(properties = {"spring.cloud.task.closecontext_enabled=false"})
public class DemoApplicationTests {
	@Test
	public void contextLoads() {
	//your test here
	}
}

如果应用里面有数据库链接,默认自动创建表,通过:

spring.cloud.task.initialize.enable=<true or false>


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
在引用中提到,spring-boot-dependencies是用于依赖管理的,而不是用于继承的。它可以帮助我们管理Spring Boot应用所需的各种依赖库的版本。而在引用[2]中提到,spring-cloud-dependencies是用于管理Spring Cloud应用所需的依赖库版本的。它可以帮助我们确保Spring Cloud应用中各个组件的版本兼容性。 另外,spring-cloud-dependencies-parent是一个用于定义Spring Cloud应用的父项目的标准。它可以帮助我们规范化和统一Spring Cloud应用的构建和依赖管理。而spring-cloud-dependencies则是在这个父项目的基础上进一步定义了各个组件的版本。 因此,spring-cloud-dependencies是用于管理Spring Cloud应用的依赖库版本的,而spring-cloud-dependencies-parent是用于定义Spring Cloud应用的父项目的标准。它们的区别在于一个是管理依赖库版本的,一个是定义父项目的标准。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [spring-boot-starter-parent 和 spring-boot-dependencies 的区别](https://blog.csdn.net/Gj1999/article/details/126621053)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* [txlcn-demo.rar](https://download.csdn.net/download/u013256012/11313360)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值