***************************
APPLICATION FAILED TO START
***************************
Description:
Field adminService in com.lilike.music.controller.AdminController required a single bean, but 2 were found:
- adminServiceImpl: defined in file [E:\music-website-master\music-server\target\classes\com\lilike\music\service\impl\AdminServiceImpl.class]
- adminServiceImpl1: defined in file [E:\music-website-master\music-server\target\classes\com\lilike\music\service\impl\AdminServiceImpl1.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
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标记为@Primary,更新使用者以接受多个bean,或者使用@Qualifier标识应该使用的bean。
AdminService的两个实现类在自动装配时冲突了,可以在其中一个实现类上加
@Primary注解,指定优先装配:
@Service
@Primary
public class AdminServiceImpl implements AdminService {
@Autowired
private AdminMapper adminMapper;
@Override
public boolean veritypasswd(String name, String password) {
return adminMapper.verifyPassword(name, password)>0?true:false;
}
}
也可以在组件上指定名字,然后用@Qualifier指定用哪个组件。
@Service("adminServiceImpl1")
public class AdminServiceImpl1 implements AdminService {
@Autowired
private AdminMapper adminMapper;
@Override
public boolean veritypasswd(String name, String password) {
return adminMapper.verifyPassword(name, password)>0?true:false;
}
}
@Service("adminServiceImpl")
public class AdminServiceImpl implements AdminService {
@Autowired
private AdminMapper adminMapper;
@Override
public boolean veritypasswd(String name, String password) {
return adminMapper.verifyPassword(name, password)>0?true:false;
}
}
@RestController
@Controller
public class AdminController {
@Autowired
@Qualifier("adminServiceImpl1")
private AdminService adminService;
……