关注「Java视界」公众号,获取更多技术干货

springboot项目启动时出现:TypeException: The alias 'XXX' is already mapped to the value 'XX' 错误

      springboot项目启动时具体报错内容如下:

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'accountController': Unsatisfied dependency expressed through field 'accountService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'accountServiceImpl': Unsatisfied dependency expressed through field 'accountDAO'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'accountDAO' defined in file [F:\gov-meeting\meeting_base\meeting_server\target\classes\com\zkml\meeting_base\server\dao\AccountDAO.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.apache.ibatis.type.TypeException: The alias 'BoardConfigInput' is already mapped to the value 'com.zkml.meeting_base.client.input.order.BoardConfigInput'.

这个错是因为mybatis的配置模糊造成的,下面的com.zkml.meeting_base意思是扫描这个路径下的po、DAO等,但是看项目工程目录,client层和server层都是这个路径,这样mybatis就会对这两个层都扫描,当出现重复map的类时就会报这个错。如下是项目的mybatis别名路径设置和项目工程目录情况:

上面的目录中这个com.zkml.meeting_base为server层和client层共有。解决办法就是把这个路径范围缩小,写得更具体一些,这里po、DAO等都在server层,因此只需要扫描server层即可,配置修改如下:

修改后项目正常启动

 

posted @ 2022-06-25 14:03  沙滩de流沙  阅读(0)  评论(0编辑  收藏  举报

关注「Java视界」公众号,获取更多技术干货