在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_providervalue =filesystem/>
< property name =tempdirvalue =#{systemProperties ['java.io.tmpdir']}/>
< property name =hibernate.search.default.indexBasevalue =$ {tempdir} \hibernate\index/>
我见过这个...
...所以它应该工作?!然而,这个变量并没有被替换,并且这些文件被写入了一个名为$ {tempdir}的新创建的子目录,这不是我想要的:)
谢谢给你的帮助!
在你研究这个之前,请通过 this explanation 关于如何读取和使用持久性xml。
$ b但是,如果您在spring上下文中配置
LocalContainerEntityManagerFactoryBean
,则persistence.xml中的字段值可以通过属性文件进行配置。 使用实体管理器工厂的 jpaPropertyMap
属性,可以配置持久性xml文件中使用的值。
以下是我的项目中使用的配置示例。
< ; bean id =entityManagerFactoryc小姑娘= org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean >
< property name =jpaPropertyMap>
< map>
< entry key =hibernate.c3p0.min_sizevalue =5/>
< entry key =hibernate.c3p0.max_sizevalue =20/>
< entry key =hibernate.c3p0.timeoutvalue =1800/>
< entry key =hibernate.dialectvalue =org.hibernate.dialect.MySQL5InnoDBDialect/>
< entry key =hibernate.search.default.indexBasevalue =$ {index.directory}/>
< / map>
< / property>
< / bean>
在上面的配置中 hibernate.search.default.indexBase $ c正在从属性文件中读取$ c>。当然你需要Spring的
PropertyPlaceholderConfigurer
来读取属性文件。
希望这有帮助。 b $ b
This has been discussed already, however none of the solutions/advices worked for me. I want to configure the lucene search index path in Spring via persistence.xml. This is important, since the deployment server is (of course) different from my local machine, so paths will not match. Right now, my configuration of hibernate-search inside the persistence.xml looks like this:
<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" />
I've seen this...
...so it should work?! However, the variable is not replaced, and the files are written to a newly created subdir having the name ${tempdir}, which is not what I wanted :)
Thanks for your help!
Before you look into this, please go through this explanation about how the persistence xml is read and used.
However, the field values in the persistence.xml are configurable through properties file, if you configure the LocalContainerEntityManagerFactoryBean
in your spring context.
Using the jpaPropertyMap
property of entity manager factory, it is possible to configure the values that are used in your persistence xml file.
Below is a sample configuration that is being used in my project.
<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>
In the above configuration hibernate.search.default.indexBase
is being read from a properties file. And of course you need Spring's PropertyPlaceholderConfigurer
to read the properties files.
Hope this helps.
这篇关于在Spring中为Hibernate Search设置动态索引目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!