关于逆向工程generatorConfig.xml报错Cannot instantiate object of type XXXX,java.lang.ClassNotFoundException分析

报错示例:

Exception in thread "main" java.lang.RuntimeException: Cannot instantiate object of type com.XXX.CommentGenerator
	at org.mybatis.generator.internal.ObjectFactory.createInternalObject(ObjectFactory.java:182)
	at org.mybatis.generator.internal.ObjectFactory.createCommentGenerator(ObjectFactory.java:239)
	at org.mybatis.generator.config.Context.getCommentGenerator(Context.java:333)
	at org.mybatis.generator.codegen.mybatis3.model.ExampleGenerator.getCompilationUnits(ExampleGenerator.java:57)
	at org.mybatis.generator.codegen.mybatis3.IntrospectedTableMyBatis3Impl.getGeneratedJavaFiles(IntrospectedTableMyBatis3Impl.java:177)
	at org.mybatis.generator.config.Context.generateFiles(Context.java:517)
	at org.mybatis.generator.api.MyBatisGenerator.generate(MyBatisGenerator.java:269)
	at org.mybatis.generator.api.MyBatisGenerator.generate(MyBatisGenerator.java:139)
	at com.XXX.mbg.Generator.main(Generator.java:35)
Caused by: java.lang.ClassNotFoundException: com.XXX.CommentGenerator
	at java.net.URLClassLoader.findClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Unknown Source)
	at org.mybatis.generator.internal.ObjectFactory.internalClassForName(ObjectFactory.java:148)
	at org.mybatis.generator.internal.ObjectFactory.createInternalObject(ObjectFactory.java:178)
	... 8 more

分析:
根据错误提示 Caused by:(引起的原因)java.lang.ClassNotFoundException,没有找到com.XXX.CommentGenerator,说明在xml配置中那个class路径有误,本示例中在commentGenerator节点,按Ctrl,鼠标放在节点上,会无法到达对应的文件,所以应该检查文件路径是否有误。
同样的原理,看网上有些是报mapper相关的错误等等,根据错误提示中的Caused by: 后面的内容,对相应的文件进行检查,

你可能感兴趣的:(Spring,Boot,Mybatis,Mybatis)