小编rob*_*non的帖子

使用Cron安排任务,允许动态更新

我使用sprint boot 1.3,spring 4.2

在这堂课上

@Service
public class PaymentServiceImpl implements PaymentService {
    ....
    @Transactional
    @Override
    public void processPayment() {
        List<Payment> payments = paymentRepository.findDuePayment();
        processCreditCardPayment(payments);
    }
}
Run Code Online (Sandbox Code Playgroud)

我想每隔x刻拨打一次processPayment.

此x时刻在数据库中设置.用户可以修改它.

所以我想我不能使用anotation.

我开始这样做了

@EntityScan(basePackageClasses = {MyApp.class,     Jsr310JpaConverters.class})
@SpringBootApplication
@EnableCaching
@EnableScheduling
public class MyApp {

    @Autowired
    private DefaultConfigService defaultConfigService;

    public static void main(String[] args) {
        SpringApplication.run(MyApp.class, args);
    }

    @Bean
    public TaskScheduler poolScheduler() {
        SimpleAsyncTaskExecutor taskScheduler = new SimpleAsyncTaskExecutor();

        DefaultConfigDto defaultConfigDto = defaultConfigService.getByFieldName("payment-cron-task");
        String cronTabExpression = "0 0 4 * * ?";
        if (defaultConfigDto != …
Run Code Online (Sandbox Code Playgroud)

spring spring-scheduled spring-boot

7
推荐指数
1
解决办法
1万
查看次数

标签 统计

spring ×1

spring-boot ×1

spring-scheduled ×1