Tuesday, May 28, 2013

Running NRepl in a Spring application - Unable to resolve symbol: original-ns

Recently I tried modifying a large Java project with Spring dependency injection such that it would start a repl server with the default namespace pre-populated with all of the Spring beans:
public class NReplConfiguration implements ApplicationContextAware {
  private static final Logger LOG = LoggerFactory.getLogger(NReplConfiguration.class);
  private static final String NREPL_INIT =
    "(use '[clojure.tools.nrepl.server :only (start-server)]) (start-server :port 7888)";

  public void setApplicationContext(ApplicationContext context) {
    Compiler.load(new StringReader(NREPL_INIT));
    for (String name : context.getBeanDefinitionNames()) {
      RT.var("user", StringUtils.uncapitalize(name), context.getBean(name));
Then trying to use leiningen to connect to the repl server, I got this error:
$ lein repl :connect 7888
REPL-y 0.1.10
Clojure 1.5.0
CompilerException java.lang.RuntimeException: Unable to resolve symbol: original-ns in this context, compiling:(null:1:12355) 
Adding this line to NReplConfiguration right after initializing the repl server made the error go away:
RT.var("complete.core", "original-ns", Symbol.create("user"));


  1. Yeah, this is fixed in REPLy 0.2.0 - see https://github.com/trptcolin/reply/issues/105

    Hope it didn't cause too much pain.

  2. That's good to hear that it's been fixed, now I can remove my hack once the fix makes it into the stable version of leiningen.