Consider marking one of the beans as @Primary, updating the consumer to accept multiple beans, or us
阿新 • • 發佈:2021-02-03
技術標籤:Springjavaspringbeanspring boot大資料
*************************** 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;
……