Really do not look at the tutorial directly use in the encounter problems will be confused, even solve problems have to search half a day is not necessarily able to help you solve ...
***************************
Application FAILED to START
***************************
Description:
Field Mapper in Com.demo.service.impl.UserServiceImpl required a bean of type ' com.demo.mapper.UserMapper ' this could not be found.
Action:
Consider defining a bean of type ' com.demo.mapper.UserMapper ' in your configuration.
Springboot start failure, tell me that the bean configuration failed, the landlord looked at the use of annotations are used on this is what the matter?
Mapper (DAO layer)
1 PackageCom.demo.mapper;2 3 ImportOrg.springframework.context.annotation.ComponentScan;4 Importorg.springframework.stereotype.Repository;5 6 ImportCom.demo.domain.User;7 8 //@Component9 @RepositoryTen Public InterfaceUsermapper { One A PublicUser Gyemian (User u); - - Public intSyemian (User u); the -}
Service
PackageCom.demo.service.impl;Importorg.springframework.beans.factory.annotation.Autowired;ImportOrg.springframework.stereotype.Service;ImportCom.demo.domain.User;ImportCom.demo.mapper.UserMapper;Importcom.demo.service.UserService; @Service (Value= "UserService") Public classUserserviceimplImplementsuserservice{@AutowiredPrivateUsermapper Mapper; @Override PublicUser Gyemian (user u) {User User=Mapper.gyemian (U); returnuser; } @Override Public intSyemian (User u) {inti =Mapper.syemian (U); returni; }}
Controller
1 PackageCom.demo.controller;2 3 Importjavax.servlet.http.HttpServletRequest;4 5 Importorg.springframework.beans.factory.annotation.Autowired;6 ImportOrg.springframework.stereotype.Controller;7 Importorg.springframework.web.bind.annotation.RequestMapping;8 ImportOrg.springframework.web.bind.annotation.ResponseBody;9 Ten ImportCom.demo.domain.User; One ImportCom.demo.service.UserService; A - @Controller -@RequestMapping (value = "/uc") the Public classUsercontroller { - - @Autowired - PrivateUserService UserService; + - @ResponseBody +@RequestMapping ("/stemp.htm") A Privatestring Syemian (String muban, HttpServletRequest request) { at -User U =NewUser (); - U.setmuban (muban); -System.out.println ("muban=" +muban); - inti =Userservice.syemian (u); - in if(i>0){ - return"Storage Succeeded"; to } + return"Storage Failed"; - } the *}
Later on the Internet to see the netizen said to use @mapper annotation, this only solves the problem for specific reasons, landlord also need to take a good look at the document to explain.
Solution:
Mapper (DAO layer)
1 PackageCom.demo.mapper;2 3 ImportOrg.apache.ibatis.annotations.Mapper;4 5 ImportCom.demo.domain.User;6 7 @Mapper8 Public InterfaceUsermapper {9 Ten PublicUser Gyemian (User u); One A Public intSyemian (User u); - -}
Spring Boot:Action:Consider Defining a bean of type ' *.*.* ' in your configuration solution