记一次Error creating bean with name ‘XXX‘: Unsatisfied ……问题/使用Mybatis-Generator 遇到的bug【存疑】

  • Post author:
  • Post category:其他


本来项目运行的好好的,但是我想打包的时候就顺手clean了一下,结果就报错了。

报错如下:

org.springframework.beans.factory.UnsatisfiedDependencyException: 
Error creating bean with name 'achieveCompetitionController': Unsatisfied dependency expressed through field 'achieveCompetitionService'; 
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'achieveCompetitionServiceImpl': Injection of resource dependencies failed; 
nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'achievementCompetitionDOMapper' defined in file [E:\last\SpringBoot\school\innovate-new\target\classes\hut\innovate\mapper\AchievementCompetitionDOMapper.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; 
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [org/mybatis/spring/boot/autoconfigure/MybatisAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: Factory method 'sqlSessionFactory' threw exception; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: 'file [E:\last\SpringBoot\school\innovate-new\target\classes\mapping\AchievementCompetitionDOMapper.xml]'; 
nested exception is org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. Cause: java.lang.IllegalArgumentException: Result Maps collection already contains value for hut.innovate.mapper.AchievementCompetitionDOMapper.BaseResultMap
 

本来视线全在前面的Error creating bean with name……上网一查都是各种注解没加,但是我真的都加了!!!实在不解。后面在后面突然发现了一个不太一样的:

Result Maps collection already contains value for hut.innovate.mapper.AchievementCompetitionDOMapper.BaseResultMap

再根据这个上网搜,得到了这样的结果:

Mybatis-Generator在生成Mapper.xml文件时,会在原来基础上再生成,导致内容重复。会报这样的错误。

话出自于

【原博客】

虽然那里说的又跟我的情况不太一样,但也给了我启发,可能是Mybatis-Generator自动生成的问题。这时我就想起教我用这个的人之前跟我说上传运行的时候要把pom文件里这些东西给注释掉:

             <plugin>
                <groupId>org.mybatis.generator</groupId>
                <artifactId>mybatis-generator-maven-plugin</artifactId>
                <version>1.3.2</version>
                <configuration>
                    <configurationFile>src/main/resources/mybatis-generator/generatorConfig.xml</configurationFile>
                    <verbose>true</verbose>
                    <overwrite>true</overwrite>
                </configuration>
                <executions>
                    <execution>
                        <id>Generate MyBatis Artifacts</id>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                    </execution>
                </executions>
                <dependencies>
                    <dependency>
                        <groupId>org.mybatis.generator</groupId>
                        <artifactId>mybatis-generator-core</artifactId>
                        <version>1.3.2</version>
                    </dependency>
                    <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
                    <dependency>
                        <groupId>mysql</groupId>
                        <artifactId>mysql-connector-java</artifactId>
                        <version>8.0.20</version>
                    </dependency>
                </dependencies>
            </plugin>

不然会有一些bug,但当时我没多问,现在吃瘪了。

后来我把最后自动生成的也就是报错的AchievementCompetitionDOMapper相关重新生成了一遍,后面把pom文件里这块注释掉了。


后面就运行成功了。

虽然还有一些疑问没解,上网也暂时搜不到,想着等那个教我的人有时间了去问问他,但这之前还是先记录一下:

1、不注释掉是会发生什么

2、为什么clean后才会出现这个bug

存疑存疑存疑



版权声明:本文为m0_46364778原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。