亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

字段XXX需要找不到類型為XXX的bean

字段XXX需要找不到類型為XXX的bean

慕絲7291255 2021-04-04 16:13:36
我在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;

}


查看完整回答
反對 回復 2021-04-21
  • 3 回答
  • 0 關注
  • 389 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號