Update samples to the latest Spring Shell and Boot versions

This commit is contained in:
Mahmoud Ben Hassine
2025-02-07 05:21:01 +01:00
parent 45350cbdfb
commit f3d582009e
20 changed files with 124 additions and 143 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015-2019 the original author or authors.
* Copyright 2015-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,10 +21,10 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.util.Map;
import org.springframework.boot.SpringApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.shell.Bootstrap;
import org.springframework.statemachine.StateContext;
import org.springframework.statemachine.action.Action;
import org.springframework.statemachine.annotation.OnTransition;
@@ -232,8 +232,8 @@ public class Application {
}
public static void main(String[] args) throws Exception {
Bootstrap.main(args);
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015-2019 the original author or authors.
* Copyright 2015-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,20 +16,19 @@
package demo.tasks;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.shell.core.annotation.CliCommand;
import org.springframework.shell.core.annotation.CliOption;
import org.springframework.stereotype.Component;
import org.springframework.shell.command.annotation.Command;
import org.springframework.shell.command.annotation.Option;
import demo.AbstractStateMachineCommands;
import demo.tasks.Application.Events;
import demo.tasks.Application.States;
import reactor.core.publisher.Mono;
@Component
@Command
public class StateMachineCommands extends AbstractStateMachineCommands<States, Events> {
@CliCommand(value = "sm event", help = "Sends an event to a state machine")
public String event(@CliOption(key = { "", "event" }, mandatory = true, help = "The event") final Events event) {
@Command(command = "sm event", description = "Sends an event to a state machine")
public String event(@Option(longNames = { "", "event" }, required = true, description = "The event") final Events event) {
getStateMachine()
.sendEvent(Mono.just(MessageBuilder
.withPayload(event).build()))

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015 the original author or authors.
* Copyright 2015-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,34 +16,32 @@
package demo.tasks;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.shell.core.CommandMarker;
import org.springframework.shell.core.annotation.CliCommand;
import org.springframework.shell.core.annotation.CliOption;
import org.springframework.stereotype.Component;
import org.springframework.shell.command.annotation.Command;
import org.springframework.shell.command.annotation.Option;
@Component
public class TasksCommands implements CommandMarker {
@Command
public class TasksCommands {
@Autowired
private Tasks tasks;
@CliCommand(value = "tasks run", help = "Run tasks")
@Command(command = "tasks run", description = "Run tasks")
public void run() {
tasks.run();
}
@CliCommand(value = "tasks list", help = "List tasks")
@Command(command = "tasks list", description = "List tasks")
public String list() {
return tasks.toString();
}
@CliCommand(value = "tasks fix", help = "Fix tasks")
@Command(command = "tasks fix", description = "Fix tasks")
public void fix() {
tasks.fix();
}
@CliCommand(value = "tasks fail", help = "Fail task")
public void fail(@CliOption(key = {"", "task"}, help = "Task id") String task) {
@Command(command = "tasks fail", description = "Fail task")
public void fail(@Option(longNames = {"", "task"}, description = "Task id") String task) {
tasks.fail(task);
}