【问题标题】:How to specify relative path for hibernate.javax.cache.uri property in xml based spring configuration如何在基于xml的spring配置中为hibernate.javax.cache.uri属性指定相对路径
【发布时间】:2018-09-24 14:33:16
【问题描述】:

我有使用基于 xml 的配置构建的遗留 Spring 应用程序我正在尝试使用二级缓存配置会话工厂。

我在资源文件夹中有ecache.xml 文件,hibernate.javax.cache.uri 属性需要ecache.xml 的绝对路径。

如果我将 URI 提供为 file:///c:/App/resources/ecache.xml 它可以工作。但这不利于部署、维护。

如何在基于 spring xml 的配置中指定相对路径,如 classpath:ehcache.xml/WEB-INF/ehcahe.xml

注意:我没有使用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>

【问题讨论】:

    标签: java hibernate spring-mvc ehcache-3


    【解决方案1】:

    好的,我可以使用 Spring EL 在基于 xml 的配置中获取绝对 uri,如下所示。

    <prop key="hibernate.javax.cache.uri">#{ new org.springframework.core.io.ClassPathResource("/ehcache.xml").getURI().toString()}</prop>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-04-06
      • 1970-01-01
      • 1970-01-01
      • 2022-11-03
      • 2014-05-01
      • 2018-08-06
      • 2014-07-05
      相关资源
      最近更新 更多