`
zhuqinglin
  • 浏览: 27582 次
  • 性别: Icon_minigender_1
  • 来自: 郑州
社区版块
存档分类
最新评论

Spring Boot:Consider defining a bean of type '*.*.*' in your configuration解决方案

    博客分类:
  • Java
 
阅读更多

    解决方案一:Mapper注解 (Dao层)

 1 package com.demo.mapper;
 2 
 3 import org.apache.ibatis.annotations.Mapper;
 4 
 5 import com.demo.domain.User;
 6 
 7 @Mapper
 8 public interface UserMapper {
 9 
10     public User gYeMian(User u);
11 
12     public int sYeMian(User u);
13 
14 }

    解决方案二:Application(启动类)

 1 package com.demo;
 2 
 3 import org.mybatis.spring.annotation.MapperScan;
 4 import org.springframework.boot.SpringApplication;
 5 import org.springframework.boot.autoconfigure.SpringBootApplication;
 6 
 7 @SpringBootApplication
 8 @MapperScan(value = "com.demo.mapper")
 9 public class App 
10 {
11     public static void main(String[] args) throws Exception {
12         SpringApplication.run(App.class, args);
13     }
14 }

    原因:在mybatis-spring-boot-autoconfigure的jar包中有一个类 MybatisAutoConfiguration,

    在这个类中的registerBeanDefinitions方法告诉了我们

 1 @Override
 2     public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, 
	BeanDefinitionRegistry registry) {
 3 
 4       logger.debug("Searching for mappers annotated with @Mapper");
 5 
 6       ClassPathMapperScanner scanner = new ClassPathMapperScanner(registry);
 7 
 8       try {
 9         if (this.resourceLoader != null) {
10           scanner.setResourceLoader(this.resourceLoader);
11         }
12 
13         List<String> packages = AutoConfigurationPackages.get(this.beanFactory);
14         if (logger.isDebugEnabled()) {
15           for (String pkg : packages) {
16             logger.debug("Using auto-configuration base package '{}'", pkg);
17           }
18         }
19 
20         scanner.setAnnotationClass(Mapper.class);
21         scanner.registerFilters();
22         scanner.doScan(StringUtils.toStringArray(packages));
23       } catch (IllegalStateException ex) {
24         logger.debug("Could not determine auto-configuration package, 
	 automatic mapper scanning disabled.", ex);
25       }
26     }

 

分享到:
评论

相关推荐

    spring boot接入微信最完整demo

    spring boot 接入微信最完整demo,包含各种微信事件。

    Addison.Wesley.C++.by.Dissection.2002.pdf

    Based on the provided information from the file "Addison.Wesley.C++.by.Dissection.2002.pdf," we can derive a comprehensive overview of the C++ programming language as covered in this text. The book is...

    spring-quartz-021

    当我们结合Spring和Quartz时,我们可以利用Spring的IoC(Inversion of Control)和AOP(Aspect-Oriented Programming)特性,轻松地管理和执行定时任务。这个名为"spring-quartz-021"的项目显然演示了如何将这两者...

    cirris operation manual

    It is designed to assist users in understanding the functionalities of the tester, ensuring they can effectively utilize it for cable testing purposes. #### Cirris Customer Support Cirris Systems ...

    Unreal Engine 4.X By Example

    In UE4, an actor is the fundamental unit of a game world. Actors can represent anything from static meshes to characters. To create a basic actor, you can use the "Add New Actor" button in the toolbar...

    google_app_engine_cheat_sheet_119_1

    This cheat sheet provides a comprehensive overview of the key functionalities and concepts related to the Datastore in Google App Engine. Understanding these features will help developers efficiently ...

    C PROGRAMMING TUTORIAL

    - **`sizeof`:** Returns the size of a variable or a data type in bytes. - **`?:`:** Conditional (ternary) operator. #### Operators Precedence in C Operators have a specific precedence that ...

    testSpring

    信息: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@15e234c: defining beans [personService]; root of factory hierarchy save()方法调用

    用友自动化测试面试题

    - **Versatile Testing**: Supports a wide range of applications, including web, desktop, and mobile. - **Robust Data Management**: Supports data-driven testing through external data sources. - **...

    Matters Computational

    - **Reversing the Bits of a Word**: Reversing the order of bits in a word. - **Bit-Wise Zip**: A technique for interlacing two sequences of bits. - **Gray Code and Parity**: Understanding Gray ...

    SCJP6 Sun Certificated Programmer for Java 6 Study Guide (Exam 310-065) 英文原版

    - **Inheritance**: How to create a hierarchy of classes by inheriting properties and behaviors from a superclass. - **Polymorphism**: Using interfaces and abstract classes to achieve polymorphism. - *...

    Manning.Spring.in.Action.4th.Edition.2014.11.epub

    Praise for the Third Edition of Spring in Action Preface Acknowledgments About this Book 1. Core Spring Chapter 1. Springing into action 1.1. Simplifying Java development 1.1.1. Unleashing the power ...

    Loving Lisp

    **Common Lisp**, in particular, is a standardized dialect of Lisp that provides a rich set of features and a comprehensive standard library, making it suitable for a wide range of applications. ...

    spring-framework-reference-4.1.2

    Aliasing a bean outside the bean definition ................................................ 28 Instantiating beans .......................................................................................

Global site tag (gtag.js) - Google Analytics