找不到java Hibernate+Spring xml映射
我有以下文件夹结构的简单应用程序:
- ProjFolder
- |-----src
- |----------包装名称
- |---------------{sourcefiles}
- |----------META-INF
- |---------------{beans.xml}
- |---------------{hibernate.cfg.xml}
- |---------------{EntityMapping.hbm.xml}
这是豆子的一部分。xml Spring配置文件:
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:./META-INF/jdbc.properties" />
</bean>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="configLocation" value="classpath:./META-INF/hibernate.cfg.xml" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>classpath:./META-INF/EntityMapping.hbm.xml</value>
</list>
</property>
</bean>
<tx:annotation-driven transaction-manager="txManager" />
<bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
当我开始单元测试时,我发现以下异常:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'wrapperClass' defined in class path resource [META-INF/beans.xml]: Cannot resolve reference to bean 'wrapperClassField' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'xmlBooksource' defined in class path resource [META-INF/beans.xml]: Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [META-INF/beans.xml]: Invocation of init method failed; nested exception is java.io.FileNotFoundException: class path resource [classpath:/META-INF/EntityMapping.hbm.xml] cannot be opened because it does not exist
当我输入时会引发相同的异常
<property name="mappingResources">
<list>
<value>EntityMapping.hbm.xml</value>
</list>
</property>
为什么spring找不到这个文件,我必须如何填充它的位置才能使代码正常工作
提前谢谢
# 1 楼答案
你试过删除} setter希望将字符串传递给^{} 。这需要类路径资源。然后字符串被传递到^{} 。这些代码都不会从资源字符串的前面去掉“classpath:”前缀
classpath:
前缀吗?在查看Hibernate代码时,^{