anchor.diff:          // 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
  +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
  +    private var exitCode = 0
  +
  +    // constructor injection
  +    constructor(factory: IFactory, myCommand: MyCommand?) {
  +        this.factory   = factory
  +        this.myCommand = myCommand
  +    }
  +
  +    override fun run(vararg args: String?) {
  +        // let picocli parse command line args and run the business logic
  +        exitCode = CommandLine(myCommand, factory).execute(*args)
  +    }
  +
  +    override fun getExitCode(): Int {
  +    return exitCode
  +    }
  +}
  +
  +fun main(args: Array<String>) {
  +    // let Spring instantiate and inject dependencies
  +    runApplication<DemoApplication>(*args)
   }
   ----
   
  
positive.code: === Spring Boot Example
  image:https://picocli.info/images/spring-boot.png[Spring Boot Logo,width=350,height=167]
  
  From 4.0, picocli provides a custom factory in the `picocli-spring-boot-starter` module.
  To use this custom factory, add the following dependency:
  
  Maven:
  
negative.code:     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
      }
  }
  ----
  