Reputation: 149
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>
Upvotes: 4
Views: 2940
Reputation: 75
Correct format is classpath://ehcache.xml
The following is not working:
classpath:ehcache.xml
classpath:/ehcache.xml
Upvotes: 0
Reputation: 149
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>
Upvotes: 4