• Mybatis Plus自动生成代码


    一、简易生成代码

    /**
     * 代码生成器
     * @since 2022-03-21
     */
    public class MpCode {
        public static void main(String[] args) {
            generate();
        }
        private  static  void generate(){
            FastAutoGenerator.create("jdbc:mysql://127.0.0.1:3306/life-sign?serverTimezone=UTC", "root", "root")
                    .globalConfig(builder -> {
                        builder.author("lh") // 设置作者
                                /*.enableSwagger() */// 开启 swagger 模式
                                .fileOverride() // 覆盖已生成文件
                                .outputDir("E:\\IDEA_MY\\life-sign\\sign-common\\sign-code\\src\\main\\java"); // 指定输出目录  和自己项目src一一对应
                    })
                    .packageConfig(builder -> {
                        builder.parent("com.luck.sign") // 设置父包名
                                .moduleName(null) // 设置父包模块名  解决路径冲突
                                .serviceImpl("service.impl") //自定义包名imp 官方的是impi
                                .entity("entity") //设置实体包为pojo
                                .pathInfo(Collections.singletonMap(OutputFile.mapperXml, "E:\\IDEA_MY\\life-sign\\sign-common\\sign-code\\src\\main\\resources\\mapper")); // 设置mapperXml生成路径
                    })
                    .strategyConfig(builder -> {
                        builder.entityBuilder().enableLombok();//使用lombok
                        builder.controllerBuilder().enableHyphenStyle()
                                .enableRestStyle();//开启RestController
                        builder.addInclude("sign_tag"); // 设置需要生成的表名
    
                    })
    //                  .templateEngine(new VelocityTemplateEngine()) // 使用Freemarker引擎模板,默认的是Velocity引擎模板
                    .execute();
        }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34

    在这里插入图片描述

    二、指定生成的样式,并且不在一个模块

    在这里插入图片描述

    1.父pom文件配置

    我是在父pom文件里进行的依赖管理

    
    <project xmlns="http://maven.apache.org/POM/4.0.0"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0modelVersion>
    
        <groupId>com.luckgroupId>
        <artifactId>life-signartifactId>
        <version>1.0-SNAPSHOTversion>
        <modules>
            <module>sign-authmodule>
            <module>sign-commonmodule>
            <module>sign-workmodule>
        modules>
    
        
        <packaging>pompackaging>
    
        <properties>
            <project.build.sourceEncoding>UTF-8project.build.sourceEncoding>
            <maven.compiler.source>1.8maven.compiler.source>
            <maven.compiler.target>1.8maven.compiler.target>
        properties>
    
        <dependencyManagement>
            <dependencies>
                
                
                <dependency>
                    <groupId>io.springfoxgroupId>
                    <artifactId>springfox-swagger-uiartifactId>
                    <version>2.9.2version>
                dependency>
    
                
                <dependency>
                    <groupId>io.springfoxgroupId>
                    <artifactId>springfox-swagger2artifactId>
                    <version>2.9.2version>
                dependency>
    
                
                <dependency>
                    <groupId>org.springframework.cloudgroupId>
                    <artifactId>spring-cloud-dependenciesartifactId>
                    <version>Hoxton.SR1version>
                    <type>pomtype>
                    <scope>importscope>
                dependency>
    
                
                <dependency>
                    <groupId>org.springframework.bootgroupId>
                    <artifactId>spring-boot-dependenciesartifactId>
                    <version>2.2.2.RELEASEversion>
                    <type>pomtype>
                    <scope>importscope>
                dependency>
    
                <dependency>
                    <groupId>mysqlgroupId>
                    <artifactId>mysql-connector-javaartifactId>
                    <version>8.0.27version>
                dependency>
                <dependency>
                    <groupId>org.mybatis.spring.bootgroupId>
                    <artifactId>mybatis-spring-boot-starterartifactId>
                    <version>2.1.4version>
                dependency>
                <dependency>
                    <groupId>com.baomidougroupId>
                    <artifactId>mybatis-plus-boot-starterartifactId>
                    <version>3.4.1version>
                dependency>
                <dependency>
                    <groupId>com.alibabagroupId>
                    <artifactId>druidartifactId>
                    <version>1.1.23version>
                dependency>
                <dependency>
                    <groupId>junitgroupId>
                    <artifactId>junitartifactId>
                    <version>4.13version>
                    <scope>testscope>
                dependency>
                
                
                <dependency>
                    <groupId>org.projectlombokgroupId>
                    <artifactId>lombokartifactId>
                    <version>1.18.22version>
                dependency>
            dependencies>
        dependencyManagement>
    
    project>
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97

    2.子模块pom文件配置

    父模块管理了依赖,对于父模块里面有的,子模块导入,就不需要写版本号了

    
    <project xmlns="http://maven.apache.org/POM/4.0.0"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <parent>
            <artifactId>sign-commonartifactId>
            <groupId>com.luckgroupId>
            <version>1.0-SNAPSHOTversion>
        parent>
        <modelVersion>4.0.0modelVersion>
        <packaging>jarpackaging>
        <artifactId>sign-codeartifactId>
        <dependencies>
            <dependency>
                <groupId>io.springfoxgroupId>
                <artifactId>springfox-swagger-uiartifactId>
            dependency>
            <dependency>
                <groupId>io.springfoxgroupId>
                <artifactId>springfox-swagger2artifactId>
            dependency>
    
            
            <dependency>
                <groupId>org.apache.velocitygroupId>
                <artifactId>velocityartifactId>
                <version>1.7version>
            dependency>
            
            <dependency>
                <groupId>com.baomidougroupId>
                <artifactId>mybatis-plus-generatorartifactId>
                <version>3.4.1version>
            dependency>
            <dependency>
                <groupId>com.baomidougroupId>
                <artifactId>mybatis-plus-boot-starterartifactId>
            dependency>
            <dependency>
                <groupId>org.springframework.bootgroupId>
                <artifactId>spring-boot-starter-webartifactId>
            dependency>
            <dependency>
                <groupId>mysqlgroupId>
                <artifactId>mysql-connector-javaartifactId>
            dependency>
            <dependency>
                <groupId>org.projectlombokgroupId>
                <artifactId>lombokartifactId>
            dependency>
        dependencies>
    
    project>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53

    以上模块的导入,针对mybatis-plus自动生成代码的功能,主要如下几个依赖

    
            
            <dependency>
                <groupId>org.apache.velocitygroupId>
                <artifactId>velocityartifactId>
                <version>1.7version>
            dependency>
            
            <dependency>
                <groupId>com.baomidougroupId>
                <artifactId>mybatis-plus-generatorartifactId>
                <version>3.4.1version>
            dependency>
            <dependency>
                <groupId>com.baomidougroupId>
                <artifactId>mybatis-plus-boot-starterartifactId>
            dependency>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17

    3.准备vm文件

    资源链接如下,若下载不了,可留言
    mybatis-plus自动生成代码的自定义引擎文件(vm文件)

    4.设置MyBatisPlusGenerator.java

    用心看,铁子们应该看的懂

    package com.luck.sign.util;
    
    
    import com.baomidou.mybatisplus.core.exceptions.MybatisPlusException;
    import com.baomidou.mybatisplus.core.toolkit.StringPool;
    import com.baomidou.mybatisplus.generator.AutoGenerator;
    import com.baomidou.mybatisplus.generator.InjectionConfig;
    import com.baomidou.mybatisplus.generator.config.*;
    import com.baomidou.mybatisplus.generator.config.po.TableInfo;
    import com.baomidou.mybatisplus.generator.config.rules.DateType;
    import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
    import com.baomidou.mybatisplus.generator.engine.VelocityTemplateEngine;
    import org.apache.commons.lang.StringUtils;
    import org.apache.commons.lang.WordUtils;
    
    import java.io.File;
    import java.util.ArrayList;
    import java.util.List;
    import java.util.Scanner;
    
    /**
     * mybatis plus 代码自动生成器
     * 参考: https://blog.csdn.net/ChunwaiLeung/article/details/121629340
     */
    public class MyBatisPlusGenerator {
        private static String module;
        private static String PACKAGE = "com.luck.sign";
        private static String AUTHOR = "lh";
        private static String DATA_USER_NAME = "root";
        private static String DATA_PASSWORD = "root";
        private static String DATA_DRIVER_NAME = "com.mysql.cj.jdbc.Driver";
        private static String DATA_URL = "jdbc:mysql://127.0.0.1:3306/life-sign?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowMultiQueries=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=Asia/Shanghai";
        private static String PATH_MAPPER  = "/src/main/java/com/luck/sign/";
        private static String PATH_MAPPER_XML = "/src/main/resources/mapper/";
        private static String PATH_CONTROLLER = "/src/main/java/com/luck/sign/";
        private static String PATH_SERVICE = "/src/main/java/com/luck/sign/";
        private static String PATH_SERVICE_IMP = "/src/main/java/com/luck/sign/";
        private static String PATH_ENTITY = "/sign-common/sign-code/src/main/java/com/luck/sign/";
    
    
        public static void main(String[] args) {
            module = "/" + scanner("要输入到哪个项目?");
            String[] tables = scanner("请输入要生成的表名多个用 , 分割").split(",");
            for (String table : tables) {
                shell(table);
            }
        }
        public static String scanner(String someThing) {
            Scanner scanner = new Scanner(System.in);
            StringBuilder help = new StringBuilder();
            help.append("请输入" + someThing + ":");
            System.out.println(help.toString());
            if (scanner.hasNext()) {
                String sc = scanner.next();
                if ("" != sc && null != sc) {
                    return sc;
                }
            }
            throw new MybatisPlusException("请输入正确的" + someThing + "!");
        }
    
        private static void shell(String table) {
            // 代码生成器
            AutoGenerator mpg = new AutoGenerator();
    
            // 数据源配置
            DataSourceConfig dsc = new DataSourceConfig();
            dsc.setDriverName(DATA_DRIVER_NAME);
            dsc.setUsername(DATA_USER_NAME);
            dsc.setPassword(DATA_PASSWORD);
            dsc.setUrl(DATA_URL);
            mpg.setDataSource(dsc);
    
            // 全局配置
            final String projectPath = System.getProperty("user.dir"); // 默认定位到的当前用户目录("user.dir")(即工程根目录) https://blog.csdn.net/qq_29964641/article/details/86686585
            GlobalConfig gc = new GlobalConfig();
            gc.setAuthor(AUTHOR);//作者名称
            gc.setDateType(DateType.ONLY_DATE);
            gc.setOpen(false); //生成后是否打开资源管理器
            gc.setServiceName("%sService"); //自定义文件命名,注意 %s 会自动填充表实体属性! %s作为占位符
            gc.setServiceImplName("%sServiceImpl");
            gc.setMapperName("%sMapper");
            gc.setXmlName("%sMapper");
            gc.setSwagger2(true);// 是否开启Swagger2模式
            gc.setFileOverride(true); //重新生成时文件是否覆盖
            gc.setActiveRecord(false);// 不需要ActiveRecord特性的请改为false
            gc.setEnableCache(false);// XML 二级缓存
            gc.setBaseResultMap(true);// XML ResultMap
            gc.setBaseColumnList(false);// XML columList
    //        gc.setIdType(IdType.ID_WORKER_STR); //主键策略
    //        gc.setOutputDir(projectPath + "/src/main/java");
    //        gc.setControllerName("%sController");
            mpg.setGlobalConfig(gc);
    
    
            // 包配置
            PackageConfig pc = new PackageConfig();
            pc.setParent(PACKAGE);
            pc.setMapper("mapper");//dao
            pc.setService("service");//servcie
            pc.setController("controller");//controller
            pc.setEntity("entity");
    //        pc.setModuleName("model名"); 自定义包名
    
            // 自定义配置
            InjectionConfig cfg = new InjectionConfig() {
                @Override
                public void initMap() {
    //                //表信息
                    String name = this.getConfig().getStrategyConfig().getColumnNaming().name();
                }
            };
    
            // 模板引擎是 freemarker
            // 自定义controller的代码模板
            // 如果模板引擎是 velocity
            String templatePath = "/template/Mapper.xml.vm";
            // 自定义输出配置
            List<FileOutConfig> focList = new ArrayList<>();
    
            // 自定义配置会被优先输出,配置mapper.xml
            focList.add(new FileOutConfig(templatePath) {
                @Override
                public String outputFile(TableInfo tableInfo) {
                    //根据自己的位置修改
                    return projectPath  + module + PATH_MAPPER_XML + tableInfo.getEntityName() + "Mapper" + StringPool.DOT_XML;
                }
            });
    
            //控制层
            templatePath = "/template/Controller.java.vm";
            // 自定义配置会被优先输出
            focList.add(new FileOutConfig(templatePath) {
                @Override
                public String outputFile(TableInfo tableInfo) {
                    // 自定义输出文件名 + pc.getModuleName()
                    String expand = projectPath  + module + PATH_CONTROLLER + "controller";
                    String entityFile = String.format((expand + File.separator + "%s" + ".java"), tableInfo.getControllerName());
                    return entityFile;
                }
            });
    
            //业务层
            templatePath = "/template/Service.java.vm";
            // 自定义配置会被优先输出
            focList.add(new FileOutConfig(templatePath) {
                @Override
                public String outputFile(TableInfo tableInfo) {
                    // 自定义输出文件名 + pc.getModuleName()
                    String expand = projectPath  + module + PATH_SERVICE + "service";
                    String entityFile = String.format((expand + File.separator + "%s" + ".java"), tableInfo.getServiceName());
                    return entityFile;
                }
            });
            templatePath = "/template/ServiceImpl.java.vm";
            // 自定义配置会被优先输出
            focList.add(new FileOutConfig(templatePath) {
                @Override
                public String outputFile(TableInfo tableInfo) {
                    // 自定义输出文件名 + pc.getModuleName()
                    String expand = projectPath  + module + PATH_SERVICE_IMP + "service/impl";
                    String entityFile = String.format((expand + File.separator + "%s" + ".java"), tableInfo.getServiceImplName());
                    return entityFile;
                }
            });
    
            //数据层
            templatePath = "/template/Mapper.java.vm";
            // 自定义配置会被优先输出
            focList.add(new FileOutConfig(templatePath) {
                @Override
                public String outputFile(TableInfo tableInfo) {
                    // 自定义输出文件名 + pc.getModuleName()
                    String expand = projectPath + module +PATH_MAPPER + "mapper";
                    String entityFile = String.format((expand + File.separator + "%s" + ".java"), tableInfo.getMapperName());
                    return entityFile;
                }
            });
    
            //数据层
            templatePath = "/template/Entity.java.vm";
            // 自定义配置会被优先输出
            focList.add(new FileOutConfig(templatePath) {
                @Override
                public String outputFile(TableInfo tableInfo) {
                    // 自定义输出文件名 + pc.getModuleName()
                    String expand = projectPath + PATH_ENTITY + "entity";
                    String entityFile = String.format((expand + File.separator + "%s" + ".java"), tableInfo.getEntityName());
                    return entityFile;
                }
            });
            mpg.setPackageInfo(pc);
            cfg.setFileOutConfigList(focList);
            mpg.setCfg(cfg);
    
    
            // 配置模板
            TemplateConfig templateConfig = new TemplateConfig();
    
            // 配置自定义输出模板
            //指定自定义模板路径,注意不要带上.ftl/.vm, 会根据使用的模板引擎自动识别
            templateConfig.setService("/template/Service.java.vm");
            templateConfig.setServiceImpl("/template/ServiceImpl.java.vm");
            templateConfig.setEntity("/template/Entity.java.vm");
            templateConfig.setMapper("/template/Mapper.java.vm");
            templateConfig.setController("/template/Controller.java.vm");
            //        //此处设置为null,就不会再java下创建xml的文件夹了
            templateConfig.setXml("/template/Mapper.xml.vm");
            mpg.setTemplate(templateConfig);
    
    
            // 策略配置
            StrategyConfig strategy = new StrategyConfig();
            strategy.setNaming(NamingStrategy.underline_to_camel); // 数据库表映射到实体的命名策略
            strategy.setColumnNaming(NamingStrategy.underline_to_camel); //数据库表字段映射到实体的命名策略
            strategy.setEntityLombokModel(true);
            strategy.setRestControllerStyle(true);
            strategy.setInclude(table); //table 表名对那一张表生成代码
            strategy.setControllerMappingHyphenStyle(true);
            strategy.setEntityLombokModel(true); // lombok 模型 @Accessors(chain = true) setter链式操作
    //        strategy.setSuperEntityClass("com.baomidou.ant.common.BaseEntity");
    //        strategy.setSuperControllerClass("com.baomidou.ant.common.BaseController"); // 公共父类
    //        strategy.setSuperEntityColumns("id"); //         写于父类中的公共字段
    //        strategy.setTablePrefix("t_");  //生成实体时去掉表前缀
    //        strategy.setRestControllerStyle(true); //restful api风格控制器
    //        strategy.setControllerMappingHyphenStyle(true); //url中驼峰转连字符
    
            mpg.setStrategy(strategy);
            mpg.setTemplateEngine(new VelocityTemplateEngine());//默认模板引擎
            mpg.execute();
    
        }
    
        /**
         * 表名转换成Java类名
         */
        private String tableToJava(String tableName, String tablePrefix) {
            if (StringUtils.isNotBlank(tablePrefix)) {
                tableName = tableName.replaceFirst(tablePrefix, "");
            }
            return columnToJava(tableName);
        }
    
        /**
         * 列名转换成Java属性名
         */
        public String columnToJava(String columnName) {
            return WordUtils.capitalizeFully(columnName, new char[]{'_'}).replace("_", "");
        }
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • 133
    • 134
    • 135
    • 136
    • 137
    • 138
    • 139
    • 140
    • 141
    • 142
    • 143
    • 144
    • 145
    • 146
    • 147
    • 148
    • 149
    • 150
    • 151
    • 152
    • 153
    • 154
    • 155
    • 156
    • 157
    • 158
    • 159
    • 160
    • 161
    • 162
    • 163
    • 164
    • 165
    • 166
    • 167
    • 168
    • 169
    • 170
    • 171
    • 172
    • 173
    • 174
    • 175
    • 176
    • 177
    • 178
    • 179
    • 180
    • 181
    • 182
    • 183
    • 184
    • 185
    • 186
    • 187
    • 188
    • 189
    • 190
    • 191
    • 192
    • 193
    • 194
    • 195
    • 196
    • 197
    • 198
    • 199
    • 200
    • 201
    • 202
    • 203
    • 204
    • 205
    • 206
    • 207
    • 208
    • 209
    • 210
    • 211
    • 212
    • 213
    • 214
    • 215
    • 216
    • 217
    • 218
    • 219
    • 220
    • 221
    • 222
    • 223
    • 224
    • 225
    • 226
    • 227
    • 228
    • 229
    • 230
    • 231
    • 232
    • 233
    • 234
    • 235
    • 236
    • 237
    • 238
    • 239
    • 240
    • 241
    • 242
    • 243
    • 244
    • 245
    • 246
    • 247
    • 248
    • 249
    • 250
    • 251

    5.运行MyBatisPlusGenerator.java文件

    在这里插入图片描述
    在这里插入图片描述

    6.运行sign-auth模块,解决异常

    问题:
    因为在MyBatisPlusGenerator.java 的全局参数配置重开启了swagger,但是模块并没有引入相关依赖
    
    • 1
    • 2
    解决:
    1.因为其他模块都会引入sign-code模块,所以在sign-code模块里引入
    2.配置swagger.config,否则swagger不能正常访问
    
            <dependency>
                <groupId>io.springfoxgroupId>
                <artifactId>springfox-swagger-uiartifactId>
            dependency>
            <dependency>
                <groupId>io.springfoxgroupId>
                <artifactId>springfox-swagger2artifactId>
            dependency>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    报错:
    org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'signOpenidController' defined in file [E:\IDEA_MY\life-sign\sign-auth\target\classes\com\luck\sign\controller\SignOpenidController.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'signOpenidServiceImpl': Unsatisfied dependency expressed through field 'baseMapper'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.luck.sign.mapper.SignOpenidMapper' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
    	at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:798) ~[spring-beans-5.2.2.RELEASE.jar:5.2.2.RELEASE]
    	... ...
    Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'signOpenidServiceImpl': Unsatisfied dependency expressed through field 'baseMapper'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.luck.sign.mapper.SignOpenidMapper' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
    	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:643) ~[spring-beans-5.2.2.RELEASE.jar:5.2.2.RELEASE]
    	... ...
    Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.luck.sign.mapper.SignOpenidMapper' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound(DefaultListableBeanFactory.java:1695) ~[spring-beans-5.2.2.RELEASE.jar:5.2.2.RELEASE]
    	... ...
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    解决方式:
    在启动类加注释 @MapperScan("com.luck.sign.mapper"),再运行即可
    
    @MapperScan("com.luck.sign.mapper")
    @SpringBootApplication
    public class AuthApplication {
        public static void main(String[] args){
            SpringApplication.run(AuthApplication.class,args);
        }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
  • 相关阅读:
    Vue学习第25天——Vuex中的4个map方法的基本用法及案例练习
    Elasticsearch 入门到精通-ElasticSearch技术原理之倒排索引的数据结构
    题解0014:信奥一本通1472——The XOR Largest Pair(字典树)
    基于SSM的学院学生论坛系统的设计与实现
    Springboot足球运动员训练计划管理系统的设计与实现 毕业设计-附源码281444
    学习typescript(1)
    部署高可用FastDFS集群时遇到的错误
    第一课 概念介绍
    探索dbus-sensors: 从传感器读取到xyz.openbmc_project.Sensor接口的细致解析
    PLL锁相环设计中的VCXO性能权衡
  • 原文地址:https://blog.csdn.net/weixin_45941687/article/details/125971980