今天在使用mybatis generator时出现了一个坑人的报错:
XML Parser Error on line 45: 元素类型为 "context" 的内容必须匹配 "(property*,plugin*,commentGenerator?,(connectionFactory|jdbcConnection),javaTypeResolver?,javaModelGenerator,sqlMapGenerator?,javaClientGenerator?,table+)"。 -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
在与官方说明核对和无数遍后发现拼写并没有错误,于是只能通过排除法来检查到底是哪个配置错了,最终定位到删除commentGenerator的配置就正常了,但是重新又核对了无数遍以后发现是没有拼写错误或其他笔误的。
<commentGenerator>
<property name="suppressAllComments" value="false"/>
<property name="addRemarkComments" value="true"/>
</commentGenerator>
于是陷入了沉思,突然想到原来在使用active mq时,有时由于配置顺序问题会产生报错,于是抱着试试看的态度将commentGenerator配置放到了context中classPathEntry后,即作为第二个自元素,再尝试运行,提示创建成功!
INFO] Generating Example class for table YMG_ENGINE
[INFO] Generating Record class for table YMG_ENGINE
[INFO] Generating Mapper Interface for table YMG_ENGINE
[INFO] Generating SQL Map for table YMG_ENGINE
[INFO] Saving file YmgEngineMapper.xml
[INFO] Saving file YmgEngineExample.java
[INFO] Saving file YmgEngine.java
[INFO] Saving file YmgEngineMapper.java
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
因此可以知道,Mybatis Generator的配置是有顺序要求的,不知道作者为什么要这样设计,对于xml配置文件,不存在顺序逻辑的配置的顺序没有限制顺序的必要吧。