播放框架 2.4.2 + spring-data-neo4j-rest

play framework 2.4.2 + spring-data-neo4j-rest

我正在尝试将 spring-data-neo4j-rest 与 Play Framework 2.4.2 一起使用。我遇到以下异常。

我在常规 java 程序中使用了相同的依赖项、控制器、存储库和实体,并在 Neo4J 数据库中成功创建了节点。将它与 Play 一起使用给了我这个例外。

AbstractApplicationContext Play 使用的 class 与 Java 程序使用的不同。

[ERROR] [08/09/2015 23:08:20.215] [application-akka.actor.default-dispatcher-3] [ActorSystem(application)] Uncaught fatal error from thread [application-akka.actor.default-dispatcher-3] shutting down ActorSystem [application]
java.lang.NoSuchMethodError: org.springframework.expression.spel.SpelParserConfiguration.<init>(Lorg/springframework/expression/spel/SpelCompilerMode;Ljava/lang/ClassLoader;)V
    at org.springframework.context.expression.StandardBeanExpressionResolver.<init>(StandardBeanExpressionResolver.java:98)
    at org.springframework.context.support.AbstractApplicationContext.prepareBeanFactory(AbstractApplicationContext.java:553)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:455)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
    at controllers.Application.index(Application.java:17)
    at router.Routes$$anonfun$routes$$anonfun$applyOrElse$$anonfun$apply.apply(Routes.scala:95)
    at router.Routes$$anonfun$routes$$anonfun$applyOrElse$$anonfun$apply.apply(Routes.scala:95)
    at play.core.routing.HandlerInvokerFactory$$anon.resultCall(HandlerInvoker.scala:136)
    at play.core.routing.HandlerInvokerFactory$JavaActionInvokerFactory$$anon$$anon$$anon.invocation(HandlerInvoker.scala:127)
    at play.core.j.JavaAction$$anon.call(JavaAction.scala:70)
    at play.http.DefaultHttpRequestHandler.call(DefaultHttpRequestHandler.java:20)
    at play.core.j.JavaAction$$anonfun.apply(JavaAction.scala:94)
    at play.core.j.JavaAction$$anonfun.apply(JavaAction.scala:94)
    at scala.concurrent.impl.Future$PromiseCompletingRunnable.liftedTree1(Future.scala:24)
    at scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:24)
    at play.core.j.HttpExecutionContext$$anon.run(HttpExecutionContext.scala:40)
    at play.api.libs.iteratee.Execution$trampoline$.execute(Execution.scala:70)
    at play.core.j.HttpExecutionContext.execute(HttpExecutionContext.scala:32)
    at scala.concurrent.impl.Future$.apply(Future.scala:31)
    at scala.concurrent.Future$.apply(Future.scala:492)
    at play.core.j.JavaAction.apply(JavaAction.scala:94)
    at play.api.mvc.Action$$anonfun$apply$$anonfun$apply$$anonfun$apply.apply(Action.scala:105)
    at play.api.mvc.Action$$anonfun$apply$$anonfun$apply$$anonfun$apply.apply(Action.scala:105)
    at play.utils.Threads$.withContextClassLoader(Threads.scala:21)
    at play.api.mvc.Action$$anonfun$apply$$anonfun$apply.apply(Action.scala:104)
    at play.api.mvc.Action$$anonfun$apply$$anonfun$apply.apply(Action.scala:103)
    at scala.Option.map(Option.scala:146)
    at play.api.mvc.Action$$anonfun$apply.apply(Action.scala:103)
    at play.api.mvc.Action$$anonfun$apply.apply(Action.scala:96)
    at play.api.libs.iteratee.Iteratee$$anonfun$mapM.apply(Iteratee.scala:524)
    at play.api.libs.iteratee.Iteratee$$anonfun$mapM.apply(Iteratee.scala:524)
    at play.api.libs.iteratee.Iteratee$$anonfun$flatMapM.apply(Iteratee.scala:560)
    at play.api.libs.iteratee.Iteratee$$anonfun$flatMapM.apply(Iteratee.scala:560)
    at play.api.libs.iteratee.Iteratee$$anonfun$flatMap$$anonfun$apply.apply(Iteratee.scala:536)
    at play.api.libs.iteratee.Iteratee$$anonfun$flatMap$$anonfun$apply.apply(Iteratee.scala:536)
    at scala.concurrent.impl.Future$PromiseCompletingRunnable.liftedTree1(Future.scala:24)
    at scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:24)
    at akka.dispatch.TaskInvocation.run(AbstractDispatcher.scala:40)
    at akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinTask.exec(AbstractDispatcher.scala:397)
    at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)
    at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339)
    at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)
    at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)

这些是 build.sbt 中用于依赖项的行

libraryDependencies += "org.springframework.data" % "spring-data-neo4j-rest" % "2.3.1.RELEASE"
libraryDependencies += "org.springframework.data" % "spring-data-neo4j" % "2.3.1.RELEASE"

applicationContext.xml:

<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:util="http://www.springframework.org/schema/util"
   xmlns:context="http://www.springframework.org/schema/context"
   xmlns:neo4j="http://www.springframework.org/schema/data/neo4j"
   xmlns:tx="http://www.springframework.org/schema/tx"
   xsi:schemaLocation="
    http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context.xsd
    http://www.springframework.org/schema/data/neo4j
    http://www.springframework.org/schema/data/neo4j/spring-neo4j.xsd
    http://www.springframework.org/schema/tx
    http://www.springframework.org/schema/tx/spring-tx.xsd">

<context:component-scan base-package="entities"/>
<neo4j:repositories base-package="entities"/>
<context:annotation-config/>
<tx:annotation-driven mode="proxy"/>
<neo4j:config graphDatabaseService="graphDatabaseService" base-package="entities"/>
<bean id="graphDatabaseService" class="org.springframework.data.neo4j.rest.SpringRestGraphDatabase">
    <constructor-arg index="0" value="http://localhost:7474/db/data" />
    <constructor-arg index="1" value="neo4j" />
    <constructor-arg index="2" value="myneo4j" />
</bean>
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/>

Application.java:

public class Application extends Controller {
    static UserController userController;
    public Result index() {
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        userController = (UserController) context.getBean("userController");
        userController.createUser();
        return ok("done!");
    }
}

UserController.java:

@Controller
public class UserController {
    @Autowired  UserRepository users;
    public void createUser() {
        User newUser = new User();
        newUser.setName("chai");
        newUser.setUsername("chai.nadig");
        users.save(newUser);
    }
}

User.java:

@NodeEntity
public class User {
    @GraphId
    Long id;
    String name;
    String username;
}

我通过使用这个插件获得了与 neo4j 一起工作的播放框架:

https://github.com/tuxBurner/play-neo4jplugin