无法运行起来

来源:2-4 Mybatis自动生成器使用方式

慕斯710447

2019-04-16 16:52

其中数据库配置

<table tableName="dw_admin" domainObjectName="AdminDO" enableCountByExample="false"
 enableSelectByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
 selectByExampleQueryId="false"></table>

    java代码

@SpringBootApplication(scanBasePackages = {"com.miaoshaproject"})
@RestController
@MapperScan("com.miaoshaproject.dao")
public class App
{
    @Autowired
    private AdminDOMapper adminDOMapper;


    @RequestMapping("/")
    public String home(){
        AdminDO adminDO = adminDOMapper.selectByPrimaryKey(1);

        if (adminDO == null){
            return "Hello world !";
        }
        else{
            return adminDO.getUserName();
        }
    }

    public static void main( String[] args ) {
        System.out.println( "Hello World!" );
        SpringApplication.run(App.class, args);
    }
}

启动报错

Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'app': Unsatisfied dependency expressed through field 'adminDOMapper'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'adminDOMapper' defined in file [/Users/pro/Desktop/java_project/target/classes/com/miaoshaproject/dao/AdminDOMapper.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 [/Users/pro/Desktop/java_project/target/classes/mapping/AdminDOMapper.xml]'; nested exception is org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. Cause: java.lang.IllegalArgumentException: Result Maps collection already contains value for com.miaoshaproject.dao.AdminDOMapper.BaseResultMap


写回答 关注

2回答

  • tongguangyu
    2019-05-08 01:17:41

    我也有这个问题 一模一样

  • zelinhehe
    2019-04-25 21:21:50

    删掉生成的文件,重新执行

SpringBoot构建电商基础秒杀项目

应用SpringBoot快速搭建拥有用户、商品、交易及秒杀活动的电商秒杀应用。

49020 学习 · 954 问题

查看课程

相似问题