Could not parse mapping document from resource Event.hbm.xml原因

本文解决了一个常见的配置头文件混淆问题,区分了配置文件头文件与映射文件头文件,并提供了正确的示例,如 hibernate.cfg.xml 和 Event.hbm.xml 的正确配置。

错误原因:主要是我们拷贝配置头文件的时候,我们大意了,没有区别他们。

注意:一个是配置文件的头文件,一个是映射文件的头文件。如下红色部分各自配置就不会报错了。

hibernate.cfg.xml:
<?xml version=
"1.0" encoding="UTF-8" ?>
<!DOCTYPE hibernate-
configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

 

 

 

 

Event.hbm.xml:
<?xml version="1.0"?>
<!DOCTYPE hibernate-
mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

### MyBatis CustomMapper.xml Not Found Solution When encountering issues where `CustomMapper.xml` is not found, several factors could contribute to this problem. Ensuring that resources are correctly loaded and accessible within the application context is crucial. #### Verify Resource Location Ensure that `CustomMapper.xml` resides in a directory included in the classpath or specified as part of the resource locations configured for MyBatis. Misplacement can lead to failure during loading attempts[^1]. #### Configuration Check Examine how configurations related to mapper XML files are set up. The provided code snippet demonstrates an aspect of parsing logic involving XPathParser and XMLMapperEntityResolver which control reading from configuration sources like `mybatis-config`. Confirm whether similar mechanisms properly locate your custom mappers: ```java public void parse() { if (!configuration.isResourceLoaded(resource)) { configurationElement(parser.evalNode("/mapper")); configuration.addLoadedResource(resource); bindMapperForNamespace(); } parsePendingResultMaps(); parsePendingCacheRefs(); parsePendingStatements(); } ``` This method ensures only unprocessed resources get evaluated while tracking what has been processed already through calls such as `isResourceLoaded()` and adding entries via `addLoadedResource()` methods[^2]. If these checks fail due to incorrect paths or naming conventions used when referencing `CustomMapper.xml`, adjustments will be necessary. #### ClassLoader Considerations ClassLoader settings might also affect locating external resources. Ensure appropriate loaders recognize directories containing `.xml` mappings so they become available at runtime without errors about missing files being reported by applications using frameworks like Spring Boot alongside MyBatis[^3]. To implement hot reloading functionality effectively (as mentioned), one approach involves configuring dynamic refresh intervals or monitoring changes made outside compiled binaries directly impacting mapped entities' behavior dynamically after deployment stages complete successfully too.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值