Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify relative path for hibernate.javax.cache.uri property in xml based spring configuration

I have legacy spring application which is built using xml based configuration I am trying to configure session factory with second level cache.

I have ecache.xml file present in resource folder also hibernate.javax.cache.uri property expects absolute path for ecache.xml.

if i provide URI as file:///c:/App/resources/ecache.xml it works. But this is not good for deployments, maintenance.

how can specify relative path like classpath:ehcache.xml or /WEB-INF/ehcahe.xml in spring xml based configurations ?

Note: I am not using spring boot.

<bean id="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <property name="packagesToScan">
            <list>
                <value>com.example.vl.model</value>
            </list>
        </property>
        <property name="configLocation" value="classpath:hibernate.cfg.xml" />
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.javax.cache.uri">file:///c:/App/resources/ecache.xml</prop>
            </props>
        </property>
    </bean>
like image 443
Nagaraju Nooka Avatar asked Oct 22 '25 05:10

Nagaraju Nooka


1 Answers

OK, I am able to get absolute uri in xml based configuration using Spring EL As follows.

<prop key="hibernate.javax.cache.uri">#{ new org.springframework.core.io.ClassPathResource("/ehcache.xml").getURI().toString()}</prop>
like image 140
Nagaraju Nooka Avatar answered Oct 24 '25 13:10

Nagaraju Nooka



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!