我在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
提交
取消