In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the conflict resolution methods used together with @ MapperScan and @ ComponentScan. The content is very detailed. Interested friends can use it for reference. I hope it will be helpful to you.
@ MapperScan and @ ComponentScan conflict with each other
The project integrates knief4j
Error report:
NoSuchBeanDefinitionException: No qualifying bean of type 'springfox.documentation.schema.TypeNameExtractor'
Obviously, the container lacks the necessary bean and the startup is not successful.
Solution one
@ MapperScan is used with @ ComponentScan
1. Build a configuration class
The startup class does not change.
Package com.test.config;import org.springframework.context.annotation.ComponentScan;import org.springframework.context.annotation.Configuration;@Configuration@ComponentScan ("com.test.bean") public class FileNameUtilsConfig {} scenario II
Start the class to make changes and use @ MapperScan to scan together
@ MapperScan (basePackages = {"com.test.mapper", "com.test.bean"}) Project where @ MapperScan and @ Mapper coexist XxxMapper that could not be found.
A young man in the company project optimized the log function of the project. Today, add dependencies to pom, add a note to the startup class, and then the startup project suddenly reports that ModuleMapper can't find it.
The project has always been good, and there are no changes to the mapper. Enter ModuleMapper and find that there is also @ Mapper annotation on it.
But why can't the container be found? analyze what has just been modified and introduce dependency annotations. The problem may be a problem on the annotations, commenting out the added annotations and starting the service to run normally. The culprit is this note.
The comment found that there is a @ MapperScan scan injection on the configuration class. Found out this guy needs to operate the database. I took charge of the project using the traditional @ Mapper injection.
Think about it: can't @ MapperScan and @ Mapper coexist in a project?
Try to solve the problem
Create your own springboot project and start launching the program with @ Mapper injection container. The program starts normally.
Stop the service, delete @ Mapper from the mapp file, move the file to the mapper file, and add @ MapperScan sweep package injection to the startup class. Start normally.
Now test @ MapperScan and @ Mapper in a non-package, respectively. Now put UserMapper in the mapper package, put UserTokenMapper in the mapper2 package, and add @ Mapper to start the test.
Startup class:
UserMapper:
UserTokenMapper:
Start the project with an error:
Description:
Field userTokenMapper in com.wyz.yangyang.member.service.impl.MemberServiceImpl required a bean of type 'com.wyz.yangyang.member.mapper2.UserTokenMapper' that could not be found.
Action:
Consider defining a bean of type 'com.wyz.yangyang.member.mapper2.UserTokenMapper' in your configuration.
Disconnected from the target VM, address: '127.0.0.1 transport: 56527 socket'
Process finished with exit code 1
Then I tested that the mapper file was not put in the package that could be scanned by @ MapperScan, and the mapper file in mapper2 was added to @ Mapper, and found that the startup was normal.
It is also tested that @ MapperScan and @ Mapper are in the same package and start up normally.
You can see here that @ MapperScan and @ Mapper have invalid @ Mapper annotations in different packages.
For rapid development of the project and for better compatibility in the future, I changed the project to @ MapperScan mode, because multiple package paths can be configured with one annotation.
So much for sharing about @ MapperScan and @ ComponentScan using conflict resolution together. I hope the above can be helpful and learn more. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.