] Failed to execute goal org.mybatis.generator:mybatis-generator-maven-plugin Cannot instantiate object of type

☆♂安♀★發表於2024-08-03
[ERROR] Failed to execute goal org.mybatis.generator:mybatis-generator-maven-plugin:1.3.7:generate (default-cli) on project com-zhianchen-pgsql: Execution default-cli of goal org.mybatis.generator:mybatis-generator-maven-plugin:1.3.7:generate failed: Cannot instantiate object of type com.xxx.MybatisCommonGenerator -> [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/PluginExecutionException

Process finished with exit code 1
因為重寫了commentGenerator類,需要自定義執行
package com.zhianchen.pgsql;

import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.config.Configuration;
import org.mybatis.generator.config.xml.ConfigurationParser;
import org.mybatis.generator.exception.InvalidConfigurationException;
import org.mybatis.generator.exception.XMLParserException;
import org.mybatis.generator.internal.DefaultShellCallback;

import java.io.File;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * @author shensr
 * @version V1.0
 * @description 透過java方式啟動mbg,實現自定配置註解,使用maven方式會出現問題
 * @create 2019/10/9
 **/

public class Generator {
    public static void main(String[] args)  {
        List<String> warnings = new ArrayList<String>();
        try {
            // true:生成的檔案覆蓋之前的
            boolean overwrite = true;
            // 讀取配置,構造 Configuration 物件.
            // 如果不想使用配置檔案的話,也可以直接來 new Configuration(),然後給相應屬性賦值.
            File configFile = new File("src\\main\\resources\\generator\\MygeneratorConfig-pgsql.xml");
            ConfigurationParser cp = new ConfigurationParser(warnings);
            Configuration config = cp.parseConfiguration(configFile);
            DefaultShellCallback callback = new DefaultShellCallback(overwrite);
            MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
            myBatisGenerator.generate(null);
        } catch (SQLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (InvalidConfigurationException e) {
            e.printStackTrace();
        } catch (XMLParserException e) {
            e.printStackTrace();
        }

        for (String warning : warnings){
            System.out.println(warning);
        }
    }
}

相關文章