0

我正在尝试将 neo4j 与 spring-data 和 scala 一起使用,但我遇到了这个异常:

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'neo4jTemplate': Invocation of init method failed; nested exception is java.lang.NoSuchMethodError:scala.collection.JavaConverters$.mapAsScalaMapConverter(Ljava/util/Map;)Lscala/collection/JavaConverters$AsScala;

目前,我不确定如何“注入”JavaConverters ...

有任何想法吗?

更新:

我试图简单地将导入放在 Test 类中:

导入 scala.collection.JavaConverters._

但是没用,完整代码如下:

WordsTest.scala

package com.dimeder.llull.security

import org.junit.runner.RunWith
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner
import org.springframework.test.context.ContextConfiguration
import org.junit.Test
import org.slf4j.LoggerFactory
import org.springframework.transaction.annotation.Transactional
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.data.neo4j.support.Neo4jTemplate
import com.dimeder.llull.models.Word
import scala.collection.JavaConverters._

@RunWith(classOf[SpringJUnit4ClassRunner])
@ContextConfiguration(Array("classpath:applicationContext-test.xml"))
class WordsTest {
         val logger = LoggerFactory.getLogger(classOf[WordsTest])

  @Autowired
  var template:Neo4jTemplate = _

  @Test
  @Transactional
  def speak(){
      val word:Word = new Word
    word.text="sustancia"
    template.save(word)
    val backWord:Word = template.findOne(word.id,classOf[Word])
    logger.info(word.text.equalsIgnoreCase(backWord.text).toString)
  }
}

applicationContext-test.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:util="http://www.springframework.org/schema/util"
       xmlns:oxm="http://www.springframework.org/schema/oxm"
       xmlns:jaxws="http://cxf.apache.org/jaxws"
       xmlns:http-conf="http://cxf.apache.org/transports/http/configuration"
       xmlns:p="http://www.springframework.org/schema/p"
       xmlns:task="http://www.springframework.org/schema/task"
       xmlns:neo4j="http://www.springframework.org/schema/data/neo4j"


       xsi:schemaLocation="http://www.springframework.org/schema/mvc
         http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
         http://www.springframework.org/schema/beans
         http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
         http://www.springframework.org/schema/context
         http://www.springframework.org/schema/context/spring-context-3.0.xsd
         http://www.springframework.org/schema/util
         http://www.springframework.org/schema/util/spring-util-3.0.xsd
         http://www.springframework.org/schema/aop
         http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
         http://www.springframework.org/schema/task
         http://www.springframework.org/schema/task/spring-task-3.0.xsd
         http://www.springframework.org/schema/data/neo4j
         http://www.springframework.org/schema/data/neo4j/spring-neo4j-2.0.xsd
        ">

    <context:spring-configured/>
    <context:annotation-config/>

    <mvc:annotation-driven/>
    <context:component-scan base-package="java.llull."/>

    <neo4j:config storeDirectory="data/graph.db"/>
    <neo4j:repositories base-package="java.llull.repositories"/>

</beans>

更新:

我解决了!

问题是 scala 版本,我使用的是 2.10,但它必须是 2.9.2

4

0 回答 0