Set dynamic index directory for Hibernate Search in Spring

烈酒焚心 提交于 2019-12-11 07:27:39

问题


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...

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

...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!


回答1:


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.



来源:https://stackoverflow.com/questions/9264931/set-dynamic-index-directory-for-hibernate-search-in-spring

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!