Skip to content

Revisit Spring Shell annotations requirement and behaviour with and without Spring Boot #1206

@fmbenhassine

Description

@fmbenhassine

As of v3.x, it is required to use @EnableCommand or @CommandScan even when using Spring Boot. This is not the opinionated Boot way of discovering/doing things, and is not consistent with the rest of the portfolio.

There is no need to use EnableXXX annotations with Spring Boot. For example, the following example (from Spring Boot's Github Homepage) is a complete working web app (notice the absence of @EnableWebMvc or EnableWebFlux):

import org.springframework.boot.*;
import org.springframework.boot.autoconfigure.*;
import org.springframework.web.bind.annotation.*;

@RestController
@SpringBootApplication
public class Example {

	@RequestMapping("/")
	String home() {
		return "Hello World!";
	}

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

}

Another example for batch applications (notice the absence of @EnableBatchProcessing from Spring Batch):

import org.springframework.boot.SpringBootApplication;
import org.springframework.batch.core.job.Job;

@SpringBootApplication
public class Example {

	@Bean
	Job job() {
		return new MyJob();
	}

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

}

The same thing should be applied for Spring Shell apps. As a Spring Shell Boot user, I am expecting the following to work:

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.shell.core.command.annotation.Command;
import org.springframework.shell.core.command.annotation.Option;

@SpringBootApplication
public class SpringShellApplication {

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

	@Command
	public String hello(@Option(defaultValue = "World") String name) {
		return "Hello " + name + "!";
	}

}

Notice the absence of @EnableCommand or @CommandScan when using Spring Boot. Those annotations should be required only when using Spring Shell without Spring Boot (in order to trigger command discovery and shell runner setup and startup).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions