Spring Boot:Action:Consider Defining a bean of type ' *.*.* ' in your configuration solution

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.