zoukankan      html  css  js  c++  java
  • ( 转)mappingResource属性和mappingDirectoryLocations属性的使用

    在Spring的applicationContext.xml中配置映射文件,通常是在这个Bean实例中进行的,若配置的映射文件较少时,可以用sessionFactory的所属类LocalSessionFactoryBean的“mappingResources”属性,定义方法如下:

    <property< span="">name="mappingResources">

       

        com/w3cs/vlar/hibernate/Person.hbm.xml

        com/w3cs/vlar/hibernate/Car.hbm.xml

        com/w3cs/vlar/hibernate/Engine.hbm.xml

        com/w3cs/vlar/hibernate/Toy.hbm.xml

       

     

    当配置文件变得越来越多,阅读和修改起来也越来越麻烦,而且基于XML的配置也可能带来输入的错误,导致你可能因为一个字符的错误而浪费半天时间去寻找错误。

    在这种情况下,可以使用LocalSessionFactoryBean的“mappingDirectoryLocations”属性来定义映射文件,只要指出映射文件所在文件夹就可以了,Spring会替你找出该文件夹内所有的映射文件,定义方法如下:

    <property< span="">name="mappingDirectoryLocations">

       

           WEB-INF/mappings

       

     

    当然,它的属性值也可以通过classpath来指出,这时所指定的是工程的类路径

    <property< span="">name="mappingDirectoryLocations">

        

             classpath:/my/package/

      

    如:

    <!-- bpaf hbm config -->
    <property name="mappingDirectoryLocations">
    <list>
    <value>/WEB-INF/classes/com/cdc/bpaf</value>
    </list>
    </property>

    摘自:http://blog.chinaunix.net/uid-20415521-id-1949853.html

     

     

  • 相关阅读:
    Karen and Game CodeForces
    Array and Segments (Easy version) CodeForces
    Diverse Garland CodeForces
    Nice Garland CodeForces
    Divisors of Two Integers CodeForces
    Two distinct points CodeForces
    Unique Snowflakes UVA
    Codeforces Round #534 (Div. 2)D. Game with modulo-1104-D(交互+二分+构造)
    关于排列组合问题的基础补充
    杭电 rescue(经典广搜)(深搜广搜对比)
  • 原文地址:https://www.cnblogs.com/antyi/p/5709896.html
Copyright © 2011-2022 走看看