玩框架2.4.2 + spring-data-neo4j-rest

时间:2015-08-10 06:19:31

标签: spring playframework neo4j spring-data-neo4j

我试图在Play Framework 2.4.2中使用spring-data-neo4j-rest。我得到以下异常。

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

AbstractApplicationContext Play使用的类与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$1$$anonfun$applyOrElse$1$$anonfun$apply$1.apply(Routes.scala:95)
    at router.Routes$$anonfun$routes$1$$anonfun$applyOrElse$1$$anonfun$apply$1.apply(Routes.scala:95)
    at play.core.routing.HandlerInvokerFactory$$anon$4.resultCall(HandlerInvoker.scala:136)
    at play.core.routing.HandlerInvokerFactory$JavaActionInvokerFactory$$anon$14$$anon$3$$anon$1.invocation(HandlerInvoker.scala:127)
    at play.core.j.JavaAction$$anon$1.call(JavaAction.scala:70)
    at play.http.DefaultHttpRequestHandler$1.call(DefaultHttpRequestHandler.java:20)
    at play.core.j.JavaAction$$anonfun$7.apply(JavaAction.scala:94)
    at play.core.j.JavaAction$$anonfun$7.apply(JavaAction.scala:94)
    at scala.concurrent.impl.Future$PromiseCompletingRunnable.liftedTree1$1(Future.scala:24)
    at scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:24)
    at play.core.j.HttpExecutionContext$$anon$2.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$1$$anonfun$apply$4$$anonfun$apply$5.apply(Action.scala:105)
    at play.api.mvc.Action$$anonfun$apply$1$$anonfun$apply$4$$anonfun$apply$5.apply(Action.scala:105)
    at play.utils.Threads$.withContextClassLoader(Threads.scala:21)
    at play.api.mvc.Action$$anonfun$apply$1$$anonfun$apply$4.apply(Action.scala:104)
    at play.api.mvc.Action$$anonfun$apply$1$$anonfun$apply$4.apply(Action.scala:103)
    at scala.Option.map(Option.scala:146)
    at play.api.mvc.Action$$anonfun$apply$1.apply(Action.scala:103)
    at play.api.mvc.Action$$anonfun$apply$1.apply(Action.scala:96)
    at play.api.libs.iteratee.Iteratee$$anonfun$mapM$1.apply(Iteratee.scala:524)
    at play.api.libs.iteratee.Iteratee$$anonfun$mapM$1.apply(Iteratee.scala:524)
    at play.api.libs.iteratee.Iteratee$$anonfun$flatMapM$1.apply(Iteratee.scala:560)
    at play.api.libs.iteratee.Iteratee$$anonfun$flatMapM$1.apply(Iteratee.scala:560)
    at play.api.libs.iteratee.Iteratee$$anonfun$flatMap$1$$anonfun$apply$13.apply(Iteratee.scala:536)
    at play.api.libs.iteratee.Iteratee$$anonfun$flatMap$1$$anonfun$apply$13.apply(Iteratee.scala:536)
    at scala.concurrent.impl.Future$PromiseCompletingRunnable.liftedTree1$1(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;
}

1 个答案:

答案 0 :(得分:0)

我使用这个插件获得了使用neo4j的游戏框架:

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