记录springboot项目启动失败required a single bean, but 2 were found

转载:http://www.513class.com/bbs/admin/1/117378.html

转载:http://www.513school.com/bbs/admin/1/117378.html

我在搭建springboot项目时,启动包如下的错误

***************************

APPLICATION FAILED TO START

***************************

Description:

Field userService in com.king.framework.web.service.UserDetailsServiceImpl required a single bean, but 2 were found:

 - sysUserServiceImpl: defined in file [D:\workspace\self\king-spring-cloud\kingSpringSecurity\target\classes\com\king\system\service\impl\SysUserServiceImpl.class]

 - ISysUserService: defined in file [D:\workspace\self\king-spring-cloud\kingSpringSecurity\target\classes\com\king\system\service\ISysUserService.class]

Action:

Consider marking one of the beans as @Primary, updating the consumer to accept multiple beans, or using @Qualifier to identify the bean that should be consumed

项目启动发现有两个重复的bean,但实际上是service只有一个接口和一个实现类

网上说 @Primary 和@Qualifier 解决但是总不能把每一个service 都加一个注解吧。

那我现在不是出现相同bean

原来我在@MapperScan扫描的时候,扫描了包括service接口和实现类的包,改成下面就可以了

@MapperScan("com.king.**.mapper")


转载:http://www.513class.com/bbs/admin/1/117378.html

转载:http://www.513school.com/bbs/admin/1/117378.html

你可能感兴趣的:(记录springboot项目启动失败required a single bean, but 2 were found)