Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I open a REPL in the context of a Spring Web Application?

I'm working on a web application based on Spring MVC and Hibernate on Tomcat 8 (both for deployment and local development). The IDE is Spring Tool Suite (which is based on Eclipse).

I want to open a REPL (read-eval-print-loop, like Groovy's, Python's, Ruby's, etc) in the context of my application (while it's running on Tomcat locally), to speed up development by shortening the code -> test feedback loop.

That is, I want to be able to open a shell in the command line (or inside Eclipse) and do something like:

ClientDAO clientDAO = getAutowiredDAOFromSpringSomehow();
Client client = clientDAO.findByID(100);
client.setName("Another name");
clientDAO.save(client);

I can work around this a bit by setting a breakpoint somewhere in a controller and use Eclipse's debugger Display tab to execute arbitrary code, but this is a bit impractical and uncomfortable.

I'm open to using Groovy or Scala's shell if it's more convenient (I obviously still need access to my objects, though).

What are my options?

like image 664
Rafael Almeida Avatar asked Aug 14 '15 12:08

Rafael Almeida


2 Answers

You may be able to do it using Spring Shell, JShell or BeanShell

Here's a project to embed a repl in an android app using BeanShell

like image 167
Brad Parks Avatar answered Sep 24 '22 08:09

Brad Parks


I don't know if it's useful for your use-case but theoretically it should be possible to do this using CRaSH. It's a Shell like Bash on Linux but for your Java-Application and it's possible to create your own commands.

like image 35
Halko Karr-Sajtarevic Avatar answered Sep 25 '22 08:09

Halko Karr-Sajtarevic