我在Spring Boot中有一個錯誤moduleContraller@RestController@RequestMapping("/module")@Validatedpublic class ModuleController { private Logger log = LoggerFactory.getLogger(this.getClass()); private final ModuleService moduleService; private final ResultGenerator generator; @Autowired public ModuleController(ModuleService moduleService, ResultGenerator generator) { this.moduleService = moduleService; this.generator = generator; } @PostMapping("/add") public RestResult addModule(@Valid Module module){ return generator.getSuccessResult("添加模塊成功", moduleService.saveModule(module)); } @GetMapping("/all") public RestResult getModule(){ return generator.getSuccessResult("查找成功", moduleService.getModule()); } @GetMapping("/{id}") public RestResult getModuleByMID(@PathVariable("id") Integer MID){ return generator.getSuccessResult("查找成功", moduleService.getModuleByMID(MID)); } @PutMapping("/edit/{id}") public RestResult editModule(@PathVariable("id") Integer MID, String title, String description){ return generator.getSuccessResult("修改成功", moduleService.editModule(MID, title, description)); } @DeleteMapping("/remove/{id}") public void removeModule(@PathVariable("id")Integer MID) { moduleService.removeModuleByID(MID); }}模塊存儲庫package org.tyrik.toys.repository;import org.springframework.data.jpa.repository.JpaRepository;import org.springframework.stereotype.Repository;import org.tyrik.toys.entity.Module;@Repositorypublic interface ModuleRepository extends JpaRepository<Module, Integer> {}還有這里的ModuleService/** * 模塊接口 */public interface ModuleService { Module saveModule(Module module); List<Module> getModule(); Optional<Module> getModuleByMID(Integer MID); Module editModule(Integer MID, String title, String description); void removeModuleByID(Integer MID);}現在我睡不著。這個問題困擾了我整整一整天,希望你們能幫助我解決這個問題。
3 回答

鳳凰求蠱
TA貢獻1825條經驗 獲得超4個贊
刪除“ ModuleServiceImpl ”豆名ModuleServiceImpl。由于您只有ModuleService接口的一種實現,因此這里不需要限定它。
@Service
public class ModuleServiceImpl implements ModuleService{
如果仍然要使用Bean名稱,請嘗試使用@Qualifier
@Autowired
public ModuleController(@Qualifier(ModuleServiceImpl) ModuleService moduleService, ResultGenerator generator)
{
this.moduleService = moduleService;
this.generator = generator;
}
添加回答
舉報
0/150
提交
取消