anchor.diff:  
       public static void main(String[] args) {
           // let Spring instantiate and inject dependencies
  -        System.exit(SpringApplication.exit(SpringApplication.run(MySpringApp.class, args)));
  -    }
  -}
  -----
  -
  -.Kotlin
  -[source,kotlin,role="secondary"]
  -----
  -import org.springframework.boot.CommandLineRunner
  -import org.springframework.boot.ExitCodeGenerator
  +        System.exit(SpringApplication.exit(SpringApplication.run(MySpringMailer.class, args)));
  +    }
  +}
  +----
  +<1> The injected factory is auto-configured to inject `PicocliSpringFactory`
  +<2> The injected `MailCommand` is our `@picocli.CommandLine.Command`-annotated class, which is listed next:
  +
  +.Kotlin
  +[source,kotlin,role="secondary"]
  +----
  +import org.springframework.boot.*
   import org.springframework.boot.autoconfigure.SpringBootApplication
  -import org.springframework.boot.runApplication
   import picocli.CommandLine
   import picocli.CommandLine.IFactory
   
   @SpringBootApplication
  -class DemoApplication : CommandLineRunner, ExitCodeGenerator {
  -
  -    private var factory: IFactory      // auto-configured to inject PicocliSpringFactory
  -    private var myCommand: MyCommand?  // your @picocli.CommandLine.Command-annotated class
  +class MySpringMailer : CommandLineRunner, ExitCodeGenerator {
  +
  +    private var factory: IFactory        // <1>
  +    private var mailCommand: MailCommand // <2>
       private var exitCode = 0
   
       // constructor injection
  -    constructor(factory: IFactory, myCommand: MyCommand?) {
  -        this.factory   = factory
  -        this.myCommand = myCommand
  -    }
  -
  -    override fun run(vararg args: String?) {
  +    constructor(factory: IFactory, mailCommand: MailCommand) {
  +        this.factory = factory          // auto-configured to inject PicocliSpringFactory
  +        this.mailCommand = mailCommand  // your @picocli.CommandLine.Command-annotated class
  +    }
  +
  +    override fun run(vararg args: String) {
           // let picocli parse command line args and run the business logic
  -        exitCode = CommandLine(myCommand, factory).execute(*args)
  +        exitCode = CommandLine(mailCommand, factory).execute(*args)
       }
   
       override fun getExitCode(): Int {
  -    return exitCode
  +        return exitCode
       }
   }
   
   fun main(args: Array<String>) {
  -    // let Spring instantiate and inject dependencies
  -    runApplication<DemoApplication>(*args)
  -}
  -----
  -
  -See the https://github.com/remkop/picocli/tree/master/picocli-spring-boot-starter[picocli-spring-boot-starter README] for another example.
  +    runApplication<MySpringMailer>(*args)
  +}
  +----
  +<1> The injected factory is auto-configured to inject `PicocliSpringFactory`
  +<2> The injected `MailCommand` is our `@picocli.CommandLine.Command`-annotated class, which is listed next:
  +
  +.Java
  +[source,java,role="primary"]
  +----
  +import org.springframework.stereotype.Component;
  +import org.springframework.beans.factory.annotation.Autowired;
  +import picocli.CommandLine.*;
  +import java.util.List;
  +import java.util.concurrent.Callable;
  +
  +@Component // <1>
  +@Command(name = "mailCommand")
  +public class MailCommand implements Callable<Integer> {
  +
  +    @Autowired private IMailService mailService; // <3>
  +
  +    @Option(names = "--to", description = "email(s) of recipient(s)", required = true)
  +    List<String> to;
  +
  +    @Option(names = "--subject", description = "Subject")
  +    String subject;
  +
  +    @Parameters(description = "Message to be sent")
  +    String[] body = {};
  +
  +    public Integer call() throws Exception {
  +        mailService.sendMessage(to, subject, String.join(" ", body)); // <2>
  +        return 0;
  +    }
  +}
  +----
  +<1> We annotate our command with the `@org.springframework.stereotype.Component` annontation so that Spring can autodetect it for dependency injection.
  +<2> The business logic of your command looks like any other picocli command with options and parameters.
  +<3> The interface for our autowired `MailService` is very simple:
  +
  +.Kotlin
  +[source,kotlin,role="secondary"]
  +----
  +import org.springframework.beans.factory.annotation.Autowired
  +import org.springframework.stereotype.Component
  +import picocli.CommandLine.*
  +import java.util.concurrent.Callable
  +
  +@Component // <1>
  +@Command(name = "mailCommand")
  +class MailCommand : Callable<Int> {
  +
  +    @Autowired private lateinit var mailService: IMailService // <3>
  +
  +    @Option(names = ["--to"], description = ["email(s) of recipient(s)"], required = true)
  +    private lateinit var to: List<String>
  +
  +    @Option(names = ["--subject"], description = ["Subject"])
  +    private var subject: String = ""
  +
  +    @Parameters(description = ["Message to be sent"])
  +    var body = arrayOf<String>()
  +
  +    @Throws(Exception::class)
  +    override fun call(): Int {
  +        mailService.sendMessage(to, subject, java.lang.String.join(" ", *body)) // <2>
  +        return 0
  +    }
  +}
  +----
  +<1> We annotate our command with the `@org.springframework.stereotype.Component` annontation so that Spring can autodetect it for dependency injection.
  +<2> The business logic of your command looks like any other picocli command with options and parameters.
  +<3> The interface for our autowired `MailService` is very simple:
  +
  +.Java
  +[source,java,role="primary"]
  +----
  +public interface IMailService {
  +    void sendMessage(List<String> to, String subject, String text);
  +}
  +----
  +.Kotlin
  +[source,kotlin,role="secondary"]
  +----
  +interface IMailService {
  +    fun sendMessage(to: List<String>, subject: String, text: String)
  +}
  +----
  +
  +And this is the implementation of our mail service:
  +
  +.Java
  +[source,java,role="primary"]
  +----
  +import org.slf4j.*;
  +import org.springframework.beans.factory.annotation.Autowired;
  +import org.springframework.mail.*;
  +import org.springframework.mail.javamail.JavaMailSender;
  +import org.springframework.stereotype.Service;
  +import java.util.List;
  +
  +@Service("MailService")
  +public class MailServiceImpl implements IMailService {
  +
  +    private static final Logger LOGGER= LoggerFactory.getLogger(MailServiceImpl.class);
  +    private static final String NOREPLY_ADDRESS = "noreply@picocli.info";
  +
  +    @Autowired private JavaMailSender emailSender; // <1>
  +
  +    @Override
  +    public void sendMessage(List<String> to, String subject, String text) {
  +        try {
  +            SimpleMailMessage message = new SimpleMailMessage(); // create message
  +            message.setFrom(NOREPLY_ADDRESS);                    // compose message
  +            for (String recipient : to) { message.setTo(recipient); }
  +            message.setSubject(subject);
  +            message.setText(text);
  +            emailSender.send(message);                           // send message
  +
  +            LOGGER.info("Mail to {} sent! Subject: {}, Body: {}", to, subject, text); // <2>
  +        }
  +        catch (MailException e) { e.printStackTrace(); }
  +    }
  +}
  +----
  +<1> The `JavaMailSender` is provided by the Spring framework.
  +<2> Once a mail was successful sent, a log message will be emitted.
  +
  +.Kotlin
  +[source,kotlin,role="secondary"]
  +----
  +import org.slf4j.LoggerFactory
  +import org.springframework.beans.factory.annotation.Autowired
  +import org.springframework.mail.*
  +import org.springframework.mail.javamail.JavaMailSender
  +import org.springframework.stereotype.Service
  +
  +@Service("MailService")
  +class MailServiceImpl : IMailService {
  +
  +    private val LOGGER = LoggerFactory.getLogger(MailServiceImpl::class.java)
  +    private val NOREPLY_ADDRESS = "noreply@picocli.info"
  +
  +    @Autowired private lateinit var emailSender: JavaMailSender // <1>
  +
  +    override fun sendMessage(to: List<String>, subject: String, text: String) {
  +        try {
  +            val message = SimpleMailMessage() // create message
  +            message.setFrom(NOREPLY_ADDRESS)  // compose message
  +            for (recipient in to) {
  +                message.setTo(recipient)
  +            }
  +            message.setSubject(subject)
  +            message.setText(text)
  +            emailSender.send(message)        // send message
  +            LOGGER.info("Mail to {} sent! Subject: {}, Body: {}", to, subject, text) // <2>
  +        } catch (e: MailException) {
  +            e.printStackTrace()
  +        }
  +    }
  +}
  +----
  +<1> The `JavaMailSender` is provided by the Spring framework.
  +<2> Once a mail was successful sent, a log message will be emitted.
  +
  +Finally we have to configure our mail service. This can be done inside a file `application properties`, which we put in a `config` subdirectory of your project:
  +
  +.application.properties
  +----
  +# configuration mail service
  +spring.mail.host=smtp.gmail.com
  +spring.mail.port=587
  +spring.mail.username=email
  +spring.mail.password=password
  +spring.mail.properties.mail.smtp.auth=true
  +spring.mail.properties.mail.smtp.starttls.enable=true
  +spring.mail.properties.mail.smtp.starttls.required=true
  +----
  +
  +With all our classes and configuration in place, we now can use the maven wrapper `mvnw` to compile and run our example app:
  +
  +----
  +mvnw spring-boot:run
  +# ...
  +  .   ____          _            __ _ _
  + /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
  +( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
  + \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  +  '  |____| .__|_| |_|_| |_\__, | / / / /
  + =========|_|==============|___/=/_/_/_/
  + :: Spring Boot ::        (v2.3.5.RELEASE)
  +# ...
  +#2020-11-01 19:35:31.084  INFO 15724 --- [           main] info.picocli.demo.MySpringMailer         : Started MySpringMailer in 0.821 seconds (JVM running for 1.131)
  +Missing required option: '--to=<to>'
  +Usage: mailCommand [--subject=<subject>] --to=<to> [--to=<to>]... [<body>...]
  +      [<body>...]           Message to be sent
  +      --subject=<subject>   Subject
  +      --to=<to>             email(s) of recipient(s)
  +----
  +
  +Since we specified no command line arguments, Picocli complains about the missing required option `--to` and outputs the usage help.
  +We have to pass in command line arguments into our command line call, we can use `-Dspring-boot.run.arguments` for that purpose:
  +
  +----
  +mvnw compile spring-boot:dev -Dspring-boot.run.arguments="--to hans@mustermann.de \
  +    --to zhang@san.cn --subject Testmail Easy mailing with Spring Boot and picocli"
  +# ...
  +2020-11-01 21:14:43.458  INFO 9656 --- [           main] info.picocli.demo.MailServiceImpl        : Mail to [hans@mustermann.de, zhang@san.cn] successfully sent! Subject:  Testmail, Body: Easy mailing with Spring Boot and picocli
  +# ...
  +----
  +
  +With all options and parameters specified, a mail is sent successfully.
   
   [TIP]
   ====
  
positive.code: ----
  ====
  
  When your command is annotated with `@org.springframework.stereotype.Component` Spring can autodetect it for dependency injection.
  The business logic of your command looks like any other picocli command with options and parameters.
  
  .Java
  [source,java,role="primary"]
  ----
  import org.springframework.stereotype.Component;
  import org.springframework.beans.factory.annotation.Autowired;
  import picocli.CommandLine.Command;
  import picocli.CommandLine.Option;
  import java.util.concurrent.Callable;
  
  @Component
  @Command(name = "myCommand")
  public class MyCommand implements Callable<Integer> {
  
      @Autowired
      private SomeService someService;
  
      // Prevent "Unknown option" error when users use
      // the Spring Boot parameter 'spring.config.location' to specify
      // an alternative location for the application.properties file.
      @Option(names = "--spring.config.location", hidden = true)
      private String springConfigLocation;
  
      @Option(names = { "-x", "--option" }, description = "example option")
      private boolean flag;
  
      public Integer call() throws Exception {
          // business logic here
          return 0;
      }
  }
  ----
  
  .Kotlin
  [source,kotlin,role="secondary"]
  ----
  import org.springframework.beans.factory.annotation.Autowired
  import org.springframework.stereotype.Component
  import picocli.CommandLine.Command
  import picocli.CommandLine.Option
  import java.util.concurrent.Callable
  
  @Component
  @Command(name = "myCommand")
  class MyCommand : Callable<Int> {
  
      @Autowired
      private var someService: SomeService? = null
  
      // Prevent "Unknown option" error when users use
      // the Spring Boot parameter 'spring.config.location' to specify
      // an alternative location for the application.properties file.
      @Option(names = ["--spring.config.location"], hidden = true)
      private lateinit var springConfigLocation: String
  
      @Option(names = ["-x", "--option"], description = ["example option"])
      private var flag = false
  
      @Throws(Exception::class)
      override fun call(): Int {
          // business logic here
          return 0
      }
  }
  ----
  
  === Micronaut Example
  image:https://micronaut.io/images/micronaut_mini_copy_tm.svg[Micronaut Logo,width=350]
  
negative.code:   header  adding custom header line(s)
  ----
  
  Since we specified no command line arguments, Picocli complains about the missing required options `--from` and `--to` and outputs the usage help.
  We have to pass in command line arguments into our command line call, we can use `-Dquarkus.args=our_values` for that purpose:
  
  ----
  