MyBatis启动时报错元素内容必须由格式正确的字符数据或标记组成

439 阅读1分钟

MyBatis手写sql时如果有<script>标签时可能会有些标签未闭合之类的报错,但是不提示具体的方法很头疼

 org.apache.ibatis.builder.BuilderException: Error creating document instance.  Cause: org.xml.sax.SAXParseException; 
 lineNumber: 1; columnNumber: 978; 元素内容必须由格式正确的字符数据或标记组成

记录下找到方法的地方

org.apache.ibatis.builder.annotation.MapperAnnotationBuilder#parse

public void parse() {
// resource 类似interface com.asiainfo.aisports.persistence.core.xxxMapper
  String resource = type.toString();
  if (!configuration.isResourceLoaded(resource)) {
    loadXmlResource();
    configuration.addLoadedResource(resource);
    assistant.setCurrentNamespace(type.getName());
    parseCache();
    parseCacheRef();
    for (Method method : type.getMethods()) {
    // 解析每个方法
      if (!canHaveStatement(method)) {
        continue;
      }
      if (getAnnotationWrapper(method, false, Select.class, SelectProvider.class).isPresent()
          && method.getAnnotation(ResultMap.class) == null) {
        parseResultMap(method);
      }
      try {
     
        parseStatement(method);
      } catch (IncompleteElementException e) {
        configuration.addIncompleteMethod(new MethodResolver(this, method));
      }
    }
  }

debug时看看是哪个方法抛出的异常,有点蠢