MyBatius BUG :Cause: org.xml.sax.SAXParseException; lineNumber: 41; columnNumber: 43; 元素内容必须由格式正确的字符数据或标记组成。
控制台打印日志如下所示
15:25:09.966 [main] ERROR o.s.b.SpringApplication - [reportFailure,837] - Application run failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'alarmBlacklistController': Unsatisfied dependency expressed through field 'iAlarmBlacklistService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'alarmBlacklistServiceImpl': Unsatisfied dependency expressed through field 'baseMapper'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'alarmBlacklistMapper' defined in file [E:\CompanyProject\\bj\mapper\AlarmBlacklistMapper.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [com/baomidou/mybatisplus/autoconfigure/MybatisPlusAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: Factory method 'sqlSessionFactory' threw exception; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: 'file [E:\CompanyProject\target\classes\mapper\bj\AlarmBlacklistMapper.xml]'; nested exception is org.apache.ibatis.builder.BuilderException: Error creating document instance. Cause: org.xml.sax.SAXParseException; lineNumber: 41; columnNumber: 43; 元素内容必须由格式正确的字符数据或标记组成。
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'alarmBlacklistServiceImpl': Unsatisfied dependency expressed through field 'baseMapper'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'alarmBlacklistMapper' defined in file [E:\CompanyProject\\mapper\AlarmBlacklistMapper.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [com/baomidou/mybatisplus/autoconfigure/MybatisPlusAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: Factory method 'sqlSessionFactory' threw exception; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: 'file [E:\CompanyProject\bj\AlarmBlacklistMapper.xml]'; nested exception is org.apache.ibatis.builder.BuilderException: Error creating document instance. Cause: org.xml.sax.SAXParseException; lineNumber: 41; columnNumber: 43; 元素内容必须由格式正确的字符数据或标记组成。
... 20 common frames omitted
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'alarmBlacklistMapper' defined in file [E:\CompanyProject\\AlarmBlacklistMapper.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [com/baomidou/mybatisplus/autoconfigure/MybatisPlusAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: Factory method 'sqlSessionFactory' threw exception; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: 'file [E:\CompanyProject\\mapper\bj\AlarmBlacklistMapper.xml]'; nested exception is org.apache.ibatis.builder.BuilderException: Error creating document instance. Cause: org.xml.sax.SAXParseException; lineNumber: 41; columnNumber: 43; 元素内容必须由格式正确的字符数据或标记组成。
... 33 common frames omitted
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [com/baomidou/mybatisplus/autoconfigure/MybatisPlusAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: Factory method 'sqlSessionFactory' threw exception; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: 'file [E:\CompanyProject\mapper\bj\AlarmBlacklistMapper.xml]'; nested exception is org.apache.ibatis.builder.BuilderException: Error creating document instance. Cause: org.xml.sax.SAXParseException; lineNumber: 41; columnNumber: 43; 元素内容必须由格式正确的字符数据或标记组成。
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:655)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireByType(AbstractAutowireCapableBeanFactory.java:1509)
... 44 common frames omitted
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: Factory method 'sqlSessionFactory' threw exception; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: 'file [E:\CompanyProject\\classes\mapper\bj\AlarmBlacklistMapper.xml]'; nested exception is org.apache.ibatis.builder.BuilderException: Error creating document instance. Cause: org.xml.sax.SAXParseException; lineNumber: 41; columnNumber: 43; 元素内容必须由格式正确的字符数据或标记组成。
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:650)
... 57 common frames omitted
Caused by: org.springframework.core.NestedIOException: Failed to parse mapping resource: 'file [E:\CompanyProject\\target\classes\mapper\bj\AlarmBlacklistMapper.xml]'; nested exception is org.apache.ibatis.builder.BuilderException: Error creating document instance. Cause: org.xml.sax.SAXParseException; lineNumber: 41; columnNumber: 43; 元素内容必须由格式正确的字符数据或标记组成。
com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean.buildSqlSessionFactory(MybatisSqlSessionFactoryBean.java:592)
... 71 common frames omitted
Caused by: org.xml.sax.SAXParseException: 元素内容必须由格式正确的字符数据或标记组成。
... 74 common frames omitted
导致该异常的原因
在使用mybatis的xml文件编写sql语句时使用<=
和>=
进行关系判断如:
<select id="listBlacklists" resultType="entity.AlarmBlacklist">
select alarm_blacklist_id,
alarm_time_blacklist,
alarm_place_blacklist,
alarm_name_blacklist,
alarm_danger_level,
alarm_level_blacklist,
alarm_operation_status
from alarm_blacklist
<where >
<if test="blacklistVo.alarmPlaceBlacklist != null">
and alarm_place_blacklist =#{blacklistVo.alarmPlaceBlacklist}
</if>
<if test="blacklistVo.alarmNameBlacklist != null">
and alarm_name_blacklist = #{blacklistVo.alarmNameBlacklist}
</if>
<if test="blacklistVo.startTime != null">
and alarm_time_blacklist >= #{blacklistVo.startTime}
</if>
<if test="blacklistVo.endTime != null">
<!--Tag name expected-->
and alarm_time_blacklist <= #{blacklistVo.endTime}
</if>
</where>
</select>
解决方案
使用实体引用来替换关系比较时要用到的<
和>
注:在 XML 中,只有字符 "<" 和 "&" 确实是非法的。大于号是合法的,但是用实体引用来代替它是一个好习惯。
< |
< | 小于 |
---|---|---|
> |
> | 大于 |
& |
& | 和号 |
' |
' | 单引号 |
" |
" | 双引号 |