【问题标题】:How to integrate spring-data-jpa and spring-data-solr?如何整合 spring-data-jpa 和 spring-data-solr?
【发布时间】:2012-11-06 07:09:35
【问题描述】:

为了启用全文搜索,我曾经使用过 hibernate-search 和 solrJ,不,我正在尝试 spring-data-solr,但发现我似乎无法与 spring-data-jpa 一起使用。我只是无法使配置正确。如果我将以下 solr 配置 xml 添加到我的项目中。我会收到错误消息。 spring-data-solr的config 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:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context"
  xmlns:solr="http://www.springframework.org/schema/data/solr" xmlns:util="http://www.springframework.org/schema/util" xmlns:cache="http://www.springframework.org/schema/cache" xmlns:security="http://www.springframework.org/schema/security"
  xsi:schemaLocation="http://www.springframework.org/schema/data/solr http://www.springframework.org/schema/data/solr/spring-solr-1.0.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
        http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security.xsd">

 <!-- 
  #####################################
  CONTEXT SETTINGS
  #####################################
   -->
  <context:property-placeholder location="classpath:laa.properties" ignore-resource-not-found="true" />

 <!-- 
  #####################################
  SOLR
  #####################################
 -->
  <solr:solr-server id="solrServer" url="${solr.host}" />

  <bean id="solrTemplate" class="org.springframework.data.solr.core.SolrTemplate" scope="singleton">
    <constructor-arg ref="solrServer" />
  </bean>

</beans>

错误信息是:

org.xml.sax.SAXParseException; systemId: http://www.springframework.org/schema/data/jpa/spring-jpa.xsd; lineNumber: 18; columnNumber: 48; src-resolve: Cannot resolve the name 'repository:repository' to a(n) 'type definition' component.
    at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
    at org.apache.xerces.util.ErrorHandlerWrapper.error(Unknown Source)
    at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
    at org.apache.xerces.impl.xs.traversers.XSDHandler.reportSchemaError(Unknown Source)
    at org.apache.xerces.impl.xs.traversers.XSDHandler.getGlobalDecl(Unknown Source)
    at org.apache.xerces.impl.xs.traversers.XSDComplexTypeTraverser.traverseComplexContent(Unknown Source)
    at org.apache.xerces.impl.xs.traversers.XSDComplexTypeTraverser.traverseComplexTypeDecl(Unknown Source)
    at org.apache.xerces.impl.xs.traversers.XSDComplexTypeTraverser.traverseGlobal(Unknown Source)
    at org.apache.xerces.impl.xs.traversers.XSDHandler.traverseSchemas(Unknown Source)
    at org.apache.xerces.impl.xs.traversers.XSDHandler.parseSchema(Unknown Source)
    at org.apache.xerces.impl.xs.XMLSchemaLoader.loadSchema(Unknown Source)
    at org.apache.xerces.impl.xs.XMLSchemaValidator.findSchemaGrammar(Unknown Source)
    at org.apache.xerces.impl.xs.XMLSchemaValidator.handleStartElement(Unknown Source)
    at org.apache.xerces.impl.xs.XMLSchemaValidator.emptyElement(Unknown Source)
    at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)

【问题讨论】:

标签: solr spring-data spring-data-jpa spring-data-solr


【解决方案1】:

您在类路径中缺少 Spring Data Commons。

【讨论】:

  • 我已将 spring-data-commons-core 添加到我的 pom.xml 文件中。在我这样做之前,maven 构建得到了 classnotfound excption。
  • 你指的是哪个版本? Spring Data JPA 1.2.0.RELEASE 和 Spring Data Solr 1.0.0.M1 都引用 Spring Data Commons 1.4.0.RELEASE 并且应该在不需要显式声明的情况下提取依赖项。
  • 在我将 Spring Data JPA 的版本从 1.1.0.RELEASE 更改为 1.2.0.RELEASE 之后。看来问题解决了。然而还有一个例外。
猜你喜欢
  • 1970-01-01
  • 2017-11-29
  • 2016-12-10
  • 1970-01-01
  • 2017-07-17
  • 1970-01-01
  • 2012-06-01
  • 2018-10-19
  • 2015-11-03
相关资源
最近更新 更多