MyBatis Generator在pom.xml中配置的configuration无效(configurationFile、overwrite等)

MyBatis Generator:MyBatis代码自动生成插件,下文简称MBG。
关于MBG的用法,可以参考:
MyBatis代码实例系列-08:通过Maven运行 MyBatis Generator,以及MyBatis Generator的扩展用法—生成中文注释和Mapper重命名为Dao

1.错误信息

在pom.xml中,在配置MBG插件时,可以通过configuration标签指定MBG的配置文件名、是否覆盖同名文件、是否将生成过程输出至控制台等,配置如下:

<configuration>
    
    <configurationFile>src/main/resources/generatorConfig.xmlconfigurationFile>
    
    <overwrite>trueoverwrite>
    
    <verbose>trueverbose>
configuration>

但是,按照如上配置,却没有生效,而且通过mybatis-generator:generate -X打印生成过程发现确实使用的是默认配置:

[DEBUG] Configuring mojo 'org.mybatis.generator:mybatis-generator-maven-plugin:1.3.2:generate' with basic configurator -->
[DEBUG]   (f) configurationFile = C:\Users\hanchao\IdeaProjects\myssm\src\main\resources\generatorConfig.xml
[DEBUG]   (f) outputDirectory = C:\Users\hanchao\IdeaProjects\myssm\target\generated-sources\mybatis-generator
[DEBUG]   (f) overwrite = false
[DEBUG]   (f) project = MavenProject: pers.hanchao:myssm:1.0-SNAPSHOT @ C:\Users\hanchao\IdeaProjects\myssm\pom.xml
[DEBUG]   (f) verbose = false
[DEBUG] -- end configuration --

2.错误分析

应该是插件配置有问题,查看完整的插件配置如下:



    org.mybatis.generator
    mybatis-generator-maven-plugin
    ${mybatis-generator.version}
    
        
        
            mysql
            mysql-connector-java
            ${mysql.version}
        
    
    
        
            mybatis-generator
            
                generate
            
            
                
                src/main/resources/generatorConfig.xml
                
                true
                
                true
            
        
    

其中,configuration标签位于executions标签中,这是错误原因。

3.错误解决

应该将configuration标签放在plugin标标签中,修改配置如下:



    org.mybatis.generator
    mybatis-generator-maven-plugin
    ${mybatis-generator.version}
    
        
        
            mysql
            mysql-connector-java
            ${mysql.version}
        
    
    
        
        src/main/resources/generatorConfig.xml
        
        true
        
        true
    
    
        
            mybatis-generator
            
                generate
            
        
    

重新运行MBG的日志信息如下:

[DEBUG] Configuring mojo 'org.mybatis.generator:mybatis-generator-maven-plugin:1.3.2:generate' with basic configurator -->
[DEBUG]   (f) configurationFile = C:\Users\hanchao\IdeaProjects\myssm\src\main\resources\generatorConfig.xml
[DEBUG]   (f) outputDirectory = C:\Users\hanchao\IdeaProjects\myssm\target\generated-sources\mybatis-generator
[DEBUG]   (f) overwrite = true
[DEBUG]   (f) project = MavenProject: pers.hanchao:myssm:1.0-SNAPSHOT @ C:\Users\hanchao\IdeaProjects\myssm\pom.xml
[DEBUG]   (f) verbose = true
[DEBUG] -- end configuration --

你可能感兴趣的:(Exception,MyBatis合集)