


How to solve the problem of empty mapper automatically injected into idea springBoot project
In the SpringBoot project, if MyBatis is used as the persistence layer framework, you may encounter the problem of mapper reporting a null pointer exception when using automatic injection. This is because SpringBoot cannot correctly identify the Mapper interface of MyBatis during automatic injection and requires some additional configuration.
There are two ways to solve this problem:
1. Add annotations to the Mapper interface
Add the @Mapper annotation to the Mapper interface to tell SpringBoot that this interface is a Mapper interface and needs to be proxied . An example is as follows:
@Mapper public interface UserMapper { // ... }
2. Manually configure the Mapper scan path
Manually configure the Mapper scan path in application.properties or application.yml to tell SpringBoot to scan the Mapper interfaces under which packages. The example is as follows:
Configure in application.properties:
mybatis.mapper-locations=classpath:mapper/*.xml
Configure in application.yml:
mybatis: mapper-locations: classpath:mapper/*.xml
It should be noted that mapper/*.xml here refers to the Mapper interface The path where the corresponding XML file is stored. If you use annotations to configure the SQL statement, you do not need to configure the XML file path.
After configuring in the above two ways, you can correctly inject the Mapper interface when using automatic injection.
Finally, if you have done all the above and still get an empty result, check whether you accidentally did not inject the mapper in the controller layer, for example
If it is a new object, the referenced injection object is not an object automatically injected into the spring container, so it will be reported as empty. You have to perform a full set of performances. Use @Autowird injection in the controller layer as well.
The above is the detailed content of How to solve the problem of empty mapper automatically injected into idea springBoot project. For more information, please follow other related articles on the PHP Chinese website!

The article discusses using Maven and Gradle for Java project management, build automation, and dependency resolution, comparing their approaches and optimization strategies.

The article discusses creating and using custom Java libraries (JAR files) with proper versioning and dependency management, using tools like Maven and Gradle.

The article discusses implementing multi-level caching in Java using Caffeine and Guava Cache to enhance application performance. It covers setup, integration, and performance benefits, along with configuration and eviction policy management best pra

The article discusses using JPA for object-relational mapping with advanced features like caching and lazy loading. It covers setup, entity mapping, and best practices for optimizing performance while highlighting potential pitfalls.[159 characters]

Java's classloading involves loading, linking, and initializing classes using a hierarchical system with Bootstrap, Extension, and Application classloaders. The parent delegation model ensures core classes are loaded first, affecting custom class loa


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Dreamweaver Mac version
Visual web development tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

Notepad++7.3.1
Easy-to-use and free code editor

Atom editor mac version download
The most popular open source editor

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.