springclojureredisrmicarmine

Integrate Spring-based Java application and Clojure library


We have a Spring 4.0-based web application running in Tomcat 8 (alternatively we have a start-up script for Undertow). Spring MVC is handling requests. I am looking for a way to defer some of request handling code to Clojure library, with minimal changes to legacy Java code.

For instance, requests with URLs ending with .java would be handled by legacy Java, and requests ending with .clj would be handled by Clojure. For now, i see three options:

  1. Include Clojure library jar in Java project's dependencies and use clojure.java.api to invoke Clojure code from Java.
  2. Use some sort of RPC/RMI or message queues, e.g. Redis and Carmine's message queue processing capabilities. This way, Clojure would live in a separate JVM.
  3. Use some sort of reverse proxy to perform URL routing.

Are above approaches actually feasible? What else would you suggest?

Thanks!


Solution

  • I've done a similar thing but on a DropWizard application rather than a Spring application. I went with approach #1.

    I followed the example here - https://stackoverflow.com/a/2187427/827617 to create the library. That way you don't need to use clojure.java.api, your Clojure library compiles down into a jar that you can include in your Spring application and call directly from Java (the functions that you expose are static methods on a class).