我有一个 Spring 项目,我正在尝试集成 Hibernate Search。除了涉及 Hibernate Search 创建索引的部分之外,该项目工作正常。
根据我从文档中了解到的情况,应该在应用程序启动时创建索引目录。没有创建索引目录,日志中也没有显示错误。我什至尝试在启动应用程序之前手动创建目录,但没有任何内容被写入其中,即使将新实体保存到数据库中也是如此。
我在 Spring 和 Hibernate 论坛上看到了许多帖子,询问如何做同样的事情,但所有这些帖子都没有得到答复,或者 OP 只是说,“我已经弄清楚了”并且没有给出任何解决方案。
此外,基于这些帖子,例如这个:Hibernate Search + Spring + JPA + 2 webapps - correct configuration,我相信如果我使用 Spring,我不需要定义单独的 persistence.xml /JPA 来管理我的实体,但我对此仍然有点不清楚。
以下是我的应用程序上下文和我的实体的相关部分。我错过了什么?
应用上下文:
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="packagesToScan" value="com.myapp" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="generateDdl" value="${db.generateDdl}" />
<property name="showSql" value="${db.showSql}" />
<property name="databasePlatform" value="${db.dialect.class}" />
</bean>
</property>
<property name="jpaPropertyMap" ref="jpaPropertyMap" />
</bean>
<util:map id="jpaPropertyMap">
<entry key="hibernate.search.default.directory_provider" value="filesystem" />
<entry key="hibernate.search.default.indexBase" value="C:\Users\Luke\indexes" />
</util:map>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
<property name="dataSource" ref="dataSource" />
</bean>
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="url" value="${db.connection.url}" />
<property name="driverClassName" value="${db.driver.class}" />
<property name="username" value="${db.username}" />
<property name="password" value="${db.password}" />
</bean>
实体:
...
@Entity
@Indexed(index = "myentity")
@Table(name = "entity_table")
public class MyEntity implements BaseEntity {
private static final long serialVersionUID = 6320371154137986977L;
@Id
@GeneratedValue
@Column(name = "id")
@DocumentId
private Long id;
@Column(name = "my_string")
@Field(index = Index.TOKENIZED,
store = Store.YES)
private String myString;
...
引导日志:
Running Jetty 6.1.26
2013-04-30 09:36:32.317:INFO::Logging to STDERR via org.mortbay.log.StdErrLog
ParentLoaderPriority enabled
Context path:/myapp
ProjectClassLoader: entry=C:\workspace-java\myapp\target\classes
ProjectClassLoader: entry=C:\Users\Luke\.m2\repository\org\scribe\scribe\1.3.3\scribe-1.3.3.jar
ProjectClassLoader: entry=C:\Users\Luke\.m2\repository\commons-codec\commons-codec\1.4\commons-codec-1.4.jar
ProjectClassLoader: entry=C:\Users\Luke\.m2\repository\javax\servlet\servlet-api\2.5\servlet-api-2.5.jar
ProjectClassLoader: entry=C:\Users\Luke\.m2\repository\org\springframework\spring-core\3.2.1.RELEASE\spring-core-3.2.1.RELEASE.jar
ProjectClassLoader: entry=C:\Users\Luke\.m2\repository\commons-logging\commons-logging\1.1.1\commons-logging-1.1.1.jar
ProjectClassLoader: entry=C:\Users\Luke\.m2\repository\org\springframework\spring-web\3.2.1.RELEASE\spring-web-3.2.1.RELEASE.jar
ProjectClassLoader: entry=C:\Users\Luke\.m2\repository\org\springframework\spring-aop\3.2.1.RELEASE\spring-aop-3.2.1.RELEASE.jar
ProjectClassLoader: entry=C:\Users\Luke\.m2\repository\org\springframework\spring-context\3.2.1.RELEASE\spring-context-3.2.1.RELEASE.jar
ProjectClassLoader: entry=C:\Users\Luke\.m2\repository\org\springframework\spring-beans\3.2.1.RELEASE\spring-beans-3.2.1.RELEASE.jar
ProjectClassLoader: entry=C:\Users\Luke\.m2\repository\aopalliance\aopalliance\1.0\aopalliance-1.0.jar
ProjectClassLoader: entry=C:\Users\Luke\.m2\repository\org\springframework\spring-webmvc\3.2.1.RELEASE\spring-webmvc-3.2.1.RELEASE.jar
ProjectClassLoader: entry=C:\Users\Luke\.m2\repository\org\springframework\spring-expression\3.2.1.RELEASE\spring-expression-3.2.1.RELEASE.jar
ProjectClassLoader: entry=C:\Users\Luke\.m2\repository\org\springframework\spring-tx\3.2.1.RELEASE\spring-tx-3.2.1.RELEASE.jar
ProjectClassLoader: entry=C:\Users\Luke\.m2\repository\org\springframework\spring-orm\3.2.1.RELEASE\spring-orm-3.2.1.RELEASE.jar
ProjectClassLoader: entry=C:\Users\Luke\.m2\repository\org\springframework\spring-test\3.2.1.RELEASE\spring-test-3.2.1.RELEASE.jar
ProjectClassLoader: entry=C:\Users\Luke\.m2\repository\org\springframework\security\spring-security-core\3.1.3.RELEASE\spring-security-core-3.1.3.RELEASE.jar
ProjectClassLoader: entry=C:\Users\Luke\.m2\repository\org\springframework\security\spring-security-web\3.1.3.RELEASE\spring-security-web-3.1.3.RELEASE.jar
ProjectClassLoader: entry=C:\Users\Luke\.m2\repository\org\springframework\spring-jdbc\3.0.7.RELEASE\spring-jdbc-3.0.7.RELEASE.jar
ProjectClassLoader: entry=C:\Users\Luke\.m2\repository\org\springframework\security\spring-security-config\3.1.3.RELEASE\spring-security-config-3.1.3.RELEASE.jar
ProjectClassLoader: entry=C:\Users\Luke\.m2\repository\org\springframework\security\spring-security-taglibs\3.1.3.RELEASE\spring-security-taglibs-3.1.3.RELEASE.jar
ProjectClassLoader: entry=C:\Users\Luke\.m2\repository\org\springframework\security\spring-security-acl\3.1.3.RELEASE\spring-security-acl-3.1.3.RELEASE.jar
ProjectClassLoader: entry=C:\Users\Luke\.m2\repository\org\hibernate\java-persistence\jpa-api\2.0-cr-1\jpa-api-2.0-cr-1.jar
ProjectClassLoader: entry=C:\Users\Luke\.m2\repository\org\springframework\data\spring-data-jpa\1.3.0.RELEASE\spring-data-jpa-1.3.0.RELEASE.jar
ProjectClassLoader: entry=C:\Users\Luke\.m2\repository\org\springframework\data\spring-data-commons\1.5.0.RELEASE\spring-data-commons-1.5.0.RELEASE.jar
ProjectClassLoader: entry=C:\Users\Luke\.m2\repository\org\aspectj\aspectjrt\1.7.1\aspectjrt-1.7.1.jar
ProjectClassLoader: entry=C:\Users\Luke\.m2\repository\org\slf4j\slf4j-api\1.7.1\slf4j-api-1.7.1.jar
ProjectClassLoader: entry=C:\Users\Luke\.m2\repository\org\slf4j\jcl-over-slf4j\1.7.1\jcl-over-slf4j-1.7.1.jar
ProjectClassLoader: entry=C:\Users\Luke\.m2\repository\org\hibernate\hibernate-validator\4.3.0.Final\hibernate-validator-4.3.0.Final.jar
ProjectClassLoader: entry=C:\Users\Luke\.m2\repository\javax\validation\validation-api\1.0.0.GA\validation-api-1.0.0.GA.jar
ProjectClassLoader: entry=C:\Users\Luke\.m2\repository\org\jboss\logging\jboss-logging\3.1.0.CR2\jboss-logging-3.1.0.CR2.jar
ProjectClassLoader: entry=C:\Users\Luke\.m2\repository\org\hibernate\hibernate-entitymanager\4.1.9.Final\hibernate-entitymanager-4.1.9.Final.jar
ProjectClassLoader: entry=C:\Users\Luke\.m2\repository\org\javassist\javassist\3.17.1-GA\javassist-3.17.1-GA.jar
ProjectClassLoader: entry=C:\Users\Luke\.m2\repository\org\jboss\spec\javax\transaction\jboss-transaction-api_1.1_spec\1.0.0.Final\jboss-transaction-api_1.1_spec-1.0.0.Final.jar
ProjectClassLoader: entry=C:\Users\Luke\.m2\repository\dom4j\dom4j\1.6.1\dom4j-1.6.1.jar
ProjectClassLoader: entry=C:\Users\Luke\.m2\repository\org\hibernate\javax\persistence\hibernate-jpa-2.0-api\1.0.1.Final\hibernate-jpa-2.0-api-1.0.1.Final.jar
ProjectClassLoader: entry=C:\Users\Luke\.m2\repository\org\hibernate\hibernate-core\4.1.9.Final\hibernate-core-4.1.9.Final.jar
ProjectClassLoader: entry=C:\Users\Luke\.m2\repository\antlr\antlr\2.7.7\antlr-2.7.7.jar
ProjectClassLoader: entry=C:\Users\Luke\.m2\repository\org\hibernate\common\hibernate-commons-annotations\4.0.1.Final\hibernate-commons-annotations-4.0.1.Final.jar
ProjectClassLoader: entry=C:\Users\Luke\.m2\repository\org\hibernate\hibernate-search\3.4.1.Final\hibernate-search-3.4.1.Final.jar
ProjectClassLoader: entry=C:\Users\Luke\.m2\repository\org\hibernate\hibernate-search-analyzers\3.4.1.Final\hibernate-search-analyzers-3.4.1.Final.jar
ProjectClassLoader: entry=C:\Users\Luke\.m2\repository\org\apache\lucene\lucene-analyzers\3.1.0\lucene-analyzers-3.1.0.jar
ProjectClassLoader: entry=C:\Users\Luke\.m2\repository\org\apache\solr\solr-analysis-extras\3.1.0\solr-analysis-extras-3.1.0.jar
ProjectClassLoader: entry=C:\Users\Luke\.m2\repository\org\apache\solr\solr-core\3.1.0\solr-core-3.1.0.jar
ProjectClassLoader: entry=C:\Users\Luke\.m2\repository\org\apache\solr\solr-solrj\3.1.0\solr-solrj-3.1.0.jar
ProjectClassLoader: entry=C:\Users\Luke\.m2\repository\org\apache\lucene\lucene-highlighter\3.1.0\lucene-highlighter-3.1.0.jar
ProjectClassLoader: entry=C:\Users\Luke\.m2\repository\org\apache\lucene\lucene-memory\3.1.0\lucene-memory-3.1.0.jar
ProjectClassLoader: entry=C:\Users\Luke\.m2\repository\org\apache\lucene\lucene-misc\3.1.0\lucene-misc-3.1.0.jar
ProjectClassLoader: entry=C:\Users\Luke\.m2\repository\org\apache\lucene\lucene-spatial\3.1.0\lucene-spatial-3.1.0.jar
ProjectClassLoader: entry=C:\Users\Luke\.m2\repository\org\apache\lucene\lucene-spellchecker\3.1.0\lucene-spellchecker-3.1.0.jar
ProjectClassLoader: entry=C:\Users\Luke\.m2\repository\org\apache\solr\solr-commons-csv\3.1.0\solr-commons-csv-3.1.0.jar
ProjectClassLoader: entry=C:\Users\Luke\.m2\repository\commons-io\commons-io\1.4\commons-io-1.4.jar
ProjectClassLoader: entry=C:\Users\Luke\.m2\repository\commons-lang\commons-lang\2.4\commons-lang-2.4.jar
ProjectClassLoader: entry=C:\Users\Luke\.m2\repository\org\apache\lucene\lucene-smartcn\3.1.0\lucene-smartcn-3.1.0.jar
ProjectClassLoader: entry=C:\Users\Luke\.m2\repository\org\apache\lucene\lucene-stempel\3.1.0\lucene-stempel-3.1.0.jar
ProjectClassLoader: entry=C:\Users\Luke\.m2\repository\org\hibernate\hibernate-commons-annotations\3.2.0.Final\hibernate-commons-annotations-3.2.0.Final.jar
ProjectClassLoader: entry=C:\Users\Luke\.m2\repository\org\apache\lucene\lucene-core\3.1.0\lucene-core-3.1.0.jar
ProjectClassLoader: entry=C:\Users\Luke\.m2\repository\mysql\mysql-connector-java\5.1.22\mysql-connector-java-5.1.22.jar
ProjectClassLoader: entry=C:\Users\Luke\.m2\repository\log4j\log4j\1.2.14\log4j-1.2.14.jar
ProjectClassLoader: entry=C:\Users\Luke\.m2\repository\org\slf4j\slf4j-log4j12\1.7.1\slf4j-log4j12-1.7.1.jar
ProjectClassLoader: entry=C:\Users\Luke\.m2\repository\jstl\jstl\1.2\jstl-1.2.jar
ProjectClassLoader: entry=C:\Users\Luke\.m2\repository\org\apache\tiles\tiles-core\3.0.1\tiles-core-3.0.1.jar
ProjectClassLoader: entry=C:\Users\Luke\.m2\repository\commons-digester\commons-digester\2.0\commons-digester-2.0.jar
ProjectClassLoader: entry=C:\Users\Luke\.m2\repository\commons-beanutils\commons-beanutils\1.8.0\commons-beanutils-1.8.0.jar
ProjectClassLoader: entry=C:\Users\Luke\.m2\repository\org\apache\tiles\tiles-api\3.0.1\tiles-api-3.0.1.jar
ProjectClassLoader: entry=C:\Users\Luke\.m2\repository\org\apache\tiles\tiles-request-api\1.0.1\tiles-request-api-1.0.1.jar
ProjectClassLoader: entry=C:\Users\Luke\.m2\repository\org\apache\tiles\tiles-jsp\3.0.1\tiles-jsp-3.0.1.jar
ProjectClassLoader: entry=C:\Users\Luke\.m2\repository\org\apache\tiles\tiles-servlet\3.0.1\tiles-servlet-3.0.1.jar
ProjectClassLoader: entry=C:\Users\Luke\.m2\repository\org\apache\tiles\tiles-request-servlet\1.0.1\tiles-request-servlet-1.0.1.jar
ProjectClassLoader: entry=C:\Users\Luke\.m2\repository\org\apache\tiles\tiles-template\3.0.1\tiles-template-3.0.1.jar
ProjectClassLoader: entry=C:\Users\Luke\.m2\repository\org\apache\tiles\tiles-autotag-core-runtime\1.1.0\tiles-autotag-core-runtime-1.1.0.jar
ProjectClassLoader: entry=C:\Users\Luke\.m2\repository\org\apache\tiles\tiles-request-jsp\1.0.1\tiles-request-jsp-1.0.1.jar
ProjectClassLoader: entry=C:\Users\Luke\.m2\repository\org\apache\httpcomponents\httpclient\4.2.3\httpclient-4.2.3.jar
ProjectClassLoader: entry=C:\Users\Luke\.m2\repository\org\apache\httpcomponents\httpcore\4.2.2\httpcore-4.2.2.jar
ProjectClassLoader: entry=C:\Users\Luke\.m2\repository\org\json\json\20090211\json-20090211.jar
ProjectClassLoader: entry=C:\Users\Luke\.m2\repository\javax\inject\javax.inject\1\javax.inject-1.jar
ProjectClassLoader: entry=C:\Users\Luke\.m2\repository\com\mysema\querydsl\querydsl-core\2.5.0\querydsl-core-2.5.0.jar
ProjectClassLoader: entry=C:\Users\Luke\.m2\repository\com\google\guava\guava\11.0.2\guava-11.0.2.jar
ProjectClassLoader: entry=C:\Users\Luke\.m2\repository\com\google\code\findbugs\jsr305\1.3.9\jsr305-1.3.9.jar
ProjectClassLoader: entry=C:\Users\Luke\.m2\repository\com\mysema\commons\mysema-commons-lang\0.2.2\mysema-commons-lang-0.2.2.jar
ProjectClassLoader: entry=C:\Users\Luke\.m2\repository\net\sourceforge\findbugs\jsr305\1.3.2\jsr305-1.3.2.jar
ProjectClassLoader: entry=C:\Users\Luke\.m2\repository\cglib\cglib\2.2\cglib-2.2.jar
ProjectClassLoader: entry=C:\Users\Luke\.m2\repository\asm\asm\3.1\asm-3.1.jar
ProjectClassLoader: entry=C:\Users\Luke\.m2\repository\com\mysema\querydsl\querydsl-jpa\2.5.0\querydsl-jpa-2.5.0.jar
ProjectClassLoader: entry=C:\Users\Luke\.m2\repository\com\mysema\querydsl\querydsl-apt\2.5.0\querydsl-apt-2.5.0.jar
ProjectClassLoader: entry=C:\Users\Luke\.m2\repository\com\mysema\querydsl\querydsl-codegen\2.5.0\querydsl-codegen-2.5.0.jar
ProjectClassLoader: entry=C:\Users\Luke\.m2\repository\com\mysema\codegen\codegen\0.4.11\codegen-0.4.11.jar
ProjectClassLoader: entry=C:\Users\Luke\.m2\repository\org\apache\commons\commons-lang3\3.1\commons-lang3-3.1.jar
ProjectClassLoader: entry=C:\Users\Luke\.m2\repository\org\mockito\mockito-all\1.9.5\mockito-all-1.9.5.jar
ProjectClassLoader: entry=C:\Users\Luke\.m2\repository\junit\junit\4.10\junit-4.10.jar
ProjectClassLoader: entry=C:\Users\Luke\.m2\repository\org\hamcrest\hamcrest-core\1.1\hamcrest-core-1.1.jar
ProjectClassLoader: entry=C:\Users\Luke\.m2\repository\javax\mail\mail\1.4\mail-1.4.jar
ProjectClassLoader: entry=C:\Users\Luke\.m2\repository\javax\activation\activation\1.1\activation-1.1.jar
ProjectClassLoader: entry=C:\Program Files\eclipse-java\plugins\org.junit_4.10.0.v4_10_0_v20120426-0900\junit.jar
ProjectClassLoader: entry=C:\Program Files\eclipse-java\plugins\org.hamcrest.core_1.1.0.v20090501071000.jar
Excluded entry=C:\workspace-java\myapp\target\test-classes
init scanning folders...
add to scan list:C:\workspace-java\myapp\target\classes
add to scan list:C:\workspace-java\myapp\src\main\webapp\WEB-INF\tiles-config.xml
add to scan list:C:\workspace-java\myapp\src\main\webapp\WEB-INF\application-context.xml
add to scan list:C:\workspace-java\myapp\src\main\webapp\WEB-INF\security-context.xml
add to scan list:C:\workspace-java\myapp\src\main\webapp\WEB-INF\application-context-base.xml
add to scan list:C:\workspace-java\myapp\src\main\webapp\WEB-INF\mvc-dispatcher-servlet.xml
add to scan list:C:\workspace-java\myapp\src\main\webapp\WEB-INF\web.xml
Starting scanner at interval of 5 seconds.
2013-04-30 09:36:32.473:INFO::jetty-6.1.26
2013-04-30 09:36:32.934:INFO:/myapp:Set web app root system property: 'webapp.root' = [C:\workspace-java\myapp\src\main\webapp]
2013-04-30 09:36:32.980:INFO:/myapp:Initializing log4j from [C:\workspace-java\myapp\src\main\webapp\WEB-INF\log4j.properties]
2013-04-30 09:36:33.033:INFO:/myapp:Initializing Spring root WebApplicationContext
2013-04-30 09:36:36.566:INFO:/myapp:Initializing Spring FrameworkServlet 'mvc-dispatcher'
2013-04-30 09:36:36.657:INFO::Started SelectChannelConnector@0.0.0.0:8080