简体   繁体   中英

Specifying path for an hbm.xml file from a different project in another project

In my Java Spring MVC Web application, I have a common project say Project A and another project say Project B . Project A only contains the common classes shared across various project and one hbm.xml -file I use and is added as dependency for all the sub projects. I have a common method to save some data to the database. I use hibernate for my database operations. I have created the hbm.xml file in Project A so that it can be used by all sub projects. In the root-context.xml file of my Project B I have the following:

   <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        <property name="dataSource">
            <ref bean="dataSource"/>
        </property>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop>
                <prop key="hibernate.show_sql">false</prop>
            </props>
        </property>

        <property name="mappingResources">
            <list>              
                <value>/hibernatemappings/support/SupportItem.hbm.xml</value>
                <value>/hibernatemappings/support/SupportPriority.hbm.xml</value>               
            </list>
        </property>
    </bean>

Now I want to add the hbm.xml -file from my Project A to this file, but I am getting a java.io.FileNotFoundException: . The base project (Project A) only has Java classes, one hbm.xml -file and do not have a web.xml or root-context.xml file.

Assuming your file is at location "Project B/src/main/resources/hibernatemappings/audit/Audit.hbm.xml"

You can get the absolute path of that file as below

this.getClass().getClassLoader().getResource("hibernatemappings/audit/Audit.hbm.xml").getPath()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM