Sivasankar Sivasankar - 4 months ago 18
Java Question

SparkJava Web get(string, Route) in the type spark is not applicable

I am building a simple REST API with Spark Java framework. I encountered this issue and not sure why this is happening. If it worked for

get("/".(req,res) -> "Hello World"


But did not work when I use

(request, response) -> {}


Am I missing any libraries?

My dependency looks like this:

<dependency>
<groupId>com.sparkjava</groupId>
<artifactId>spark-core</artifactId>
<version>2.5</version>
</dependency>


import static spark.Spark.*;
public class HelloWorld {
public static void main(String[] args) {
get("/",(request, response) -> {
});
post("/transaction/add", (request, response) -> {
});
}
}


Error message for the method:

enter image description here

Answer

It's Route source.

@FunctionalInterface
public interface Route {
    Object handle(Request arg0, Response arg1) throws Exception;
}

You have to return Object in lambda expression!

Comments