title: Spring Boot Kotlin API returns 404 response for all endpoints
body: <p>I'm using Spring Boot with Kotlin . The rest controller returns 404 error for all endpoints. In the starting logs the endpoints in the controller are not present. Any endpoint returns the same 404 response.</p>
  
  <p>These are the steps I have tried,</p>
  
  <ol>
  <li>Tried clearing cache/target</li>
  <li>Moved all classes into single directory</li>
  <li>Tried adding ComponentScan annotation but it is not accepted.</li>
  <li>I'm using cmd line to run the project</li>
  <li>Same output seen when running java -jar $jarfile</li>
  <li>Checked annotations Repository , Service , RestController</li>
  </ol>
  
  <p>Controller:</p>
  
  <pre><code>package com.example.controller
  
  import org.springframework.web.bind.annotation.RestController
  import org.springframework.web.bind.annotation.PathVariable
  import org.springframework.http.ResponseEntity
  import org.springframework.web.bind.annotation.GetMapping
  import org.springframework.http.HttpStatus
  import org.springframework.web.bind.annotation.PostMapping
  import org.springframework.web.bind.annotation.PutMapping
  import org.springframework.web.bind.annotation.DeleteMapping
  import org.springframework.web.bind.annotation.RequestBody
  
  import Cricketer
  import CricketerRepository
  import CricketerService
  import org.springframework.web.bind.annotation.RequestMapping
  
  @RestController
  @RequestMapping("/api")
  class CricketerController(private val cricketerService: CricketerService , private val cricketerRepository: CricketerRepository){
  
      @GetMapping("/cricketers/{id}")
      fun getCricketer(@PathVariable("id") id: Long):ResponseEntity&lt;Cricketer&gt;  {
          val cricketer = cricketerService.findById(id)
          return ResponseEntity&lt;Cricketer&gt;(cricketer as Cricketer, HttpStatus.OK);
      }
  
      @GetMapping("/cricketers/")
      fun getAllCricketers() :ResponseEntity&lt;List&lt;Cricketer&gt;&gt;  {
          var cricketersList: ArrayList&lt;Cricketer&gt; =  cricketerService.getAllPlayers() as (ArrayList&lt;Cricketer&gt;)
          return ResponseEntity&lt;List&lt;Cricketer&gt;&gt;(cricketersList, HttpStatus.OK)
      }
  
      @PostMapping("/cricketer/")
      fun addCricketer(@RequestBody cricketer:Cricketer):ResponseEntity&lt;Cricketer&gt;  {
          val cCricketer : Cricketer = Cricketer(name = cricketer.name
                  , country = cricketer.country
                  , highestScore = cricketer.highestScore)
          cricketerRepository.save(cCricketer)
          return ResponseEntity&lt;Cricketer&gt;(cricketer , HttpStatus.OK)
      }
  
      @PutMapping("/cricketer/{id}")
      fun updateCricketer(@PathVariable("id") id: Long, @RequestBody cricketer: Cricketer ):ResponseEntity&lt;Cricketer&gt; {
          val cCricketer  = Cricketer(name = cricketer.name
                  , country = cricketer.country
                  , highestScore = cricketer.highestScore)
          cricketerRepository.save(cCricketer)
          return ResponseEntity&lt;Cricketer&gt;(cricketer, HttpStatus.OK)
      }
  
      @DeleteMapping("/cricketer/{id}")
      fun deleteCricketer(@PathVariable("id") id:Long ):ResponseEntity&lt;String&gt; {
          val cCricketer :Cricketer  = cricketerService.findById(id) as Cricketer
          cricketerRepository.delete(cCricketer)
          return ResponseEntity&lt;String&gt;("cricketer removed", HttpStatus.OK)
      }
  }
  </code></pre>
  
  <p>pom.xml </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  
      &lt;groupId&gt;com.example&lt;/groupId&gt;
      &lt;artifactId&gt;Spring-Kotlin-Rest-API&lt;/artifactId&gt;
      &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
      &lt;packaging&gt;jar&lt;/packaging&gt;
  
      &lt;name&gt;Spring-Kotlin-Rest-API&lt;/name&gt;
      &lt;description&gt;Spring Boot Kotlin REST API Example&lt;/description&gt;
  
      &lt;parent&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
          &lt;version&gt;2.0.2.RELEASE&lt;/version&gt;
          &lt;relativePath/&gt; &lt;!-- lookup parent from repository --&gt;
      &lt;/parent&gt;
  
      &lt;properties&gt;
          &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
          &lt;project.reporting.outputEncoding&gt;UTF-8&lt;/project.reporting.outputEncoding&gt;
          &lt;java.version&gt;1.8&lt;/java.version&gt;
          &lt;kotlin.version&gt;1.2.41&lt;/kotlin.version&gt;
  
      &lt;/properties&gt;
  
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-data-jpa&lt;/artifactId&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.fasterxml.jackson.module&lt;/groupId&gt;
              &lt;artifactId&gt;jackson-module-kotlin&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.jetbrains.kotlin&lt;/groupId&gt;
              &lt;artifactId&gt;kotlin-stdlib-jdk8&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.jetbrains.kotlin&lt;/groupId&gt;
              &lt;artifactId&gt;kotlin-reflect&lt;/artifactId&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;mysql&lt;/groupId&gt;
              &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
              &lt;scope&gt;runtime&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
      &lt;/dependencies&gt;
  
      &lt;build&gt;
          &lt;sourceDirectory&gt;${project.basedir}/src/main/kotlin&lt;/sourceDirectory&gt;
          &lt;testSourceDirectory&gt;${project.basedir}/src/test/kotlin&lt;/testSourceDirectory&gt;
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;       
              &lt;/plugin&gt;
              &lt;plugin&gt;
                  &lt;artifactId&gt;kotlin-maven-plugin&lt;/artifactId&gt;
                  &lt;groupId&gt;org.jetbrains.kotlin&lt;/groupId&gt;
                  &lt;configuration&gt;
                      &lt;args&gt;
                          &lt;arg&gt;-Xjsr305=strict&lt;/arg&gt;
                      &lt;/args&gt;
  
                      &lt;compilerPlugins&gt;
  
                          &lt;plugin&gt;spring&lt;/plugin&gt;
                      &lt;/compilerPlugins&gt;
                      &lt;jvmTarget&gt;1.8&lt;/jvmTarget&gt;          
                  &lt;/configuration&gt;
                  &lt;dependencies&gt;
                      &lt;dependency&gt;
                          &lt;groupId&gt;org.jetbrains.kotlin&lt;/groupId&gt;
                          &lt;artifactId&gt;kotlin-maven-allopen&lt;/artifactId&gt;
                          &lt;version&gt;${kotlin.version}&lt;/version&gt;
                      &lt;/dependency&gt;
                  &lt;/dependencies&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/build&gt;
  &lt;/project&gt;
  </code></pre>
  
  <p>Startup logs</p>
  
  <pre><code>2018-05-21 22:31:19.490  INFO 3061 --- [           main] c.e.d.SpringKotlinRestApiApplicationKt   : Starting SpringKotlinRestApiApplicationKt on nirmal-desktop with PID 3061 (/home/nirmal/code/workspace-sts-3.9.1.RELEASE/Spring-Kotlin-Rest-API/target/classes started by root in /home/nirmal/code/workspace-sts-3.9.1.RELEASE/Spring-Kotlin-Rest-API)
  2018-05-21 22:31:19.512  INFO 3061 --- [           main] c.e.d.SpringKotlinRestApiApplicationKt   : No active profile set, falling back to default profiles: default
  2018-05-21 22:31:19.592  INFO 3061 --- [           main] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@5bab7c16: startup date [Mon May 21 22:31:19 IST 2018]; root of context hierarchy
  2018-05-21 22:31:29.492  INFO 3061 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$28d3b505] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
  2018-05-21 22:31:33.847  INFO 3061 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
  2018-05-21 22:31:34.312  INFO 3061 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
  2018-05-21 22:31:34.313  INFO 3061 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.31
  2018-05-21 22:31:34.389  INFO 3061 --- [ost-startStop-1] o.a.catalina.core.AprLifecycleListener   : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib]
  2018-05-21 22:31:36.190  INFO 3061 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
  2018-05-21 22:31:36.190  INFO 3061 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 16602 ms
  2018-05-21 22:31:36.560  INFO 3061 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Servlet dispatcherServlet mapped to [/]
  2018-05-21 22:31:36.564  INFO 3061 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*]
  2018-05-21 22:31:36.566  INFO 3061 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
  2018-05-21 22:31:36.566  INFO 3061 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'httpPutFormContentFilter' to: [/*]
  2018-05-21 22:31:36.566  INFO 3061 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'requestContextFilter' to: [/*]
  2018-05-21 22:31:37.743  INFO 3061 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
  2018-05-21 22:31:39.038  INFO 3061 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
  2018-05-21 22:31:39.222  INFO 3061 --- [           main] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'default'
  2018-05-21 22:31:39.480  INFO 3061 --- [           main] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [
      name: default
      ...]
  2018-05-21 22:31:40.064  INFO 3061 --- [           main] org.hibernate.Version                    : HHH000412: Hibernate Core {5.2.17.Final}
  2018-05-21 22:31:40.066  INFO 3061 --- [           main] org.hibernate.cfg.Environment            : HHH000206: hibernate.properties not found
  2018-05-21 22:31:40.302  INFO 3061 --- [           main] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
  2018-05-21 22:31:42.180  INFO 3061 --- [           main] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.MySQL5InnoDBDialect
  2018-05-21 22:31:44.235  INFO 3061 --- [           main] o.h.t.schema.internal.SchemaCreatorImpl  : HHH000476: Executing import script 'org.hibernate.tool.schema.internal.exec.ScriptSourceInputNonExistentImpl@7d95eb4a'
  2018-05-21 22:31:44.237  INFO 3061 --- [           main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
  2018-05-21 22:31:44.688  INFO 3061 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
  2018-05-21 22:31:46.829  INFO 3061 --- [           main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@5bab7c16: startup date [Mon May 21 22:31:19 IST 2018]; root of context hierarchy
  2018-05-21 22:31:46.894  WARN 3061 --- [           main] aWebConfiguration$JpaWebMvcConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
  2018-05-21 22:31:47.072  INFO 3061 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
  2018-05-21 22:31:47.073  INFO 3061 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity&lt;java.util.Map&lt;java.lang.String, java.lang.Object&gt;&gt; org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
  2018-05-21 22:31:47.121  INFO 3061 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
  2018-05-21 22:31:47.122  INFO 3061 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
  2018-05-21 22:31:49.030  INFO 3061 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
  2018-05-21 22:31:49.033  INFO 3061 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Bean with name 'dataSource' has been autodetected for JMX exposure
  2018-05-21 22:31:49.047  INFO 3061 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Located MBean 'dataSource': registering with JMX server as MBean [com.zaxxer.hikari:name=dataSource,type=HikariDataSource]
  2018-05-21 22:31:50.682  INFO 3061 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
  2018-05-21 22:31:50.695  INFO 3061 --- [           main] c.e.d.SpringKotlinRestApiApplicationKt   : Started SpringKotlinRestApiApplicationKt in 34.697 seconds (JVM running for 49.043)
  </code></pre>