繁体   English   中英

在Spring中为Hibernate Search设置动态索引目录

[英]Set dynamic index directory for Hibernate Search in Spring

已经讨论过了,但是没有解决方案/建议对我有用。 我想通过persistence.xml在Spring中配置Lucene搜索索引路径。 这很重要,因为部署服务器(当然)与我的本地计算机不同,因此路径将不匹配。 现在,我在persistence.xml中的hibernate-search配置如下所示:

<property name="hibernate.search.default.directory_provider" value="filesystem" /> 
<property name="tempdir" value="#{ systemProperties['java.io.tmpdir'] }" />
<property name="hibernate.search.default.indexBase" value="${tempdir}\hibernate\index" /> 

我见过这个......

http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/expressions.html#expressions-beandef-xml-based

...所以它应该工作?! 但是,该变量未被替换,并且文件被写入新创建的名为$ {tempdir}的子目录,这不是我想要的:)

谢谢你的帮助!

在研究此内容之前,请仔细阅读以下有关如何读取和使用持久性xml的说明

但是,如果在spring上下文中配置LocalContainerEntityManagerFactoryBean ,则persistence.xml中的字段值可通过属性文件进行配置。

使用实体管理器工厂的jpaPropertyMap属性,可以配置在持久性xml文件中使用的值。

以下是在我的项目中使用的示例配置。

<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="jpaPropertyMap">
        <map>
            <entry key="hibernate.c3p0.min_size" value="5"/>
            <entry key="hibernate.c3p0.max_size" value="20"/>
            <entry key="hibernate.c3p0.timeout" value="1800"/>
            <entry key="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect"/>
            <entry key="hibernate.search.default.indexBase" value="${index.directory}"/>
        </map>
    </property>
</bean>

在上述配置中,正在从属性文件读取hibernate.search.default.indexBase 当然,您需要Spring的PropertyPlaceholderConfigurer来读取属性文件。

希望这可以帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM