spring、hibernate整合出现“does not denote a directory”

在整合spring、hibernate时,mapping映射文件出现does not denote a directory错误。

错误日志:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Mapping directory location [file [F:\workspace\hr\HrSystem\bin\com\zhueli\soft\hr\entity\HrAccount.hbm.xml]] does not denote a directory

配置文件applicationContext.xml
[code="java"]<?xml version="1.0" encoding="UTF-8"?>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">

<bean id="propertyConfigurer"
    class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="locations">
        <list>
            <value>classpath:dbinit.properties</value>
        </list>
    </property>
</bean>

<bean id="sessionFactory"
    class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">
                ${hibernate.dialect}
            </prop>
            <prop key="hibernate.show_sql">
                ${hibernate.show_sql}
            </prop>
            <prop key="hibernate.cache.use_query_cache">
                ${hibernate.cache.use_query_cache}
            </prop>
            <prop key="hibernate.cache.provider_class">
                ${hibernate.cache.provider_class}
            </prop>
        </props>
    </property>

    <property name="mappingDirectoryLocations">
        <list>
            <value>
                classpath*:/com/zhueli/soft/hr/entity/*.hbm.xml
            </value>
        </list>
    </property>
    <property name="lobHandler" ref="lobHandler" />
</bean>

<bean id="lobHandler" lazy-init="true"
    class="org.springframework.jdbc.support.lob.DefaultLobHandler" />
<aop:config>
    <aop:advisor
        pointcut="execution(* com.zhueli.soft.hr.service.*.*(..))"
        advice-ref="txAdvice" />

    <aop:advisor
        pointcut="execution(* com.zhueli.soft.hr.*.*.service.*.*(..))"
        advice-ref="txAdvice" />
    <aop:advisor
        pointcut="execution(* com.zhueli.soft.hr.*.service.*.*(..))"
        advice-ref="txAdvice" />
    <aop:advisor
        pointcut="execution(* com.zhueli.soft.hr.*.*.*.service.*.*(..))"
        advice-ref="txAdvice" />
</aop:config>

<tx:advice id="txAdvice">
    <tx:attributes>
        <tx:method name="insert*" />
        <tx:method name="save*" />
        <tx:method name="create*" />
        <tx:method name="add*" />
        <tx:method name="update*" />
        <tx:method name="modify*" />
        <tx:method name="delete*" />
        <tx:method name="remove*" />
        <tx:method name="send*" />
        <tx:method name="do*" />
        <tx:method name="*" read-only="true" />
    </tx:attributes>
</tx:advice>

<bean id="baseDao" class="com.zhueli.soft.hr.db.BaseDaoImpl">
    <property name="sessionFactory" ref="sessionFactory" />
</bean>

<import resource="classpath:dataAccessContext-local.xml" />

[/code]

经检查项目不存在中文,实体类目录也确实生成了。

2个回答







[color=red]classpath*:/com/zhueli/soft/hr/entity/*.hbm.xml [/color]






[b]你这个地方写的不对吧,mappingDirectoryLocations属性说的就是目录位置,你为什么还要*.hbm.xml 呢,指定到目录就可以了classpath*:/com/zhueli/soft/hr/entity/[/b]

[code="xml"]





classpath*:/com/zhueli/soft/hr/entity/*.hbm.xml





[/code]
把property的name属性值改为mappingResources。即
[code="xml"]





classpath*:/com/zhueli/soft/hr/entity/*.hbm.xml





[/code]

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问