Search code examples
scalascalatra

Scalatra does not mount new service


I am trying to mount the service to scalatra but after compiling and starting the app GET /logging is not recognized by scalatra

ScalatraBootstrap.scala

import org.scalatra._
import javax.servlet.ServletContext


class ScalatraBootstrap extends LifeCycle {
  override  def init(context: ServletContext): Unit = {
    context mount(new LoggingService, "/logging/*")
  }
}

LoggingService.scala

import org.scalatra._

class LoggingService extends ScalatraServlet {
  get("/*") {
    "hello"
  }
}

I get

Requesting "GET /logging/" on servlet "" but only have:
GET /

Thanks in advance


Solution

  • Maybe this will solve it.

    get("/") {
       "hello"
    }
    

    context mount(new LoggingService, "/logging/*")
    

    The "/logging/*" means that it will add all with prefix /logging/


    Example

    get("/") {
        "hello"
    }
    
    get("/1") {
        "hello1"
    }
    
    get("/2") {
        "hello2"
    }
    

    use with "/logging", "/logging/1" or "/logging/2"