In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the @ Autowired annotation injected xxxMapper error report how to do, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.
@ Autowired comment injected xxxMapper error project scenario
Mybatis-Plus test
Problem description
In the test of the Mybatis-Plus scenario, it is found that the userMapper injected through the @ Autowired annotation will report an error.
This is because UserMapper is not a class that can create objects, but an interface.
@ Override public void run () {bytes = mmInStream.read (buffer); mHandler.obtainMessage (READ_DATA, bytes,-1, buffer). SendToTarget ();} solution
Option 1:
By adding @ Repository annotations.
Option 2:
Without using the @ Repository annotation, you can achieve injection by changing the @ Autowired annotation to the @ Resource annotation.
Analysis.
@ Autowired will report an error because the interface is not implemented
1. @ Autowired performs bean matching in byType mode by default, and @ Resource matches bean in byName mode by default.
2. @ Autowired is the annotation of Spring, and @ Resource is the annotation of J2EE. The package names of these two annotations are clear when you take a look at the import of annotations.
Spring belongs to a third party, and J2EE is Java's own thing, so it is recommended to use @ Resource annotations to reduce the coupling between code and Spring.
@ Autowired failed to load Mapper with an error of 404 or 500
When I have been misarranging, looking for annotations to add less or the database can not get the file, carelessness deceived me.
When @ Autowired fails to load Mapper and reports an error of 404or 500, you should pay more attention to the following points
Whether the package name is the same, and whether the package name is the same when loading the Mapper interface
Whether or not Autowired has been added to private XXXMapper xxxmapper;. If the startup class cannot start the display, it must be added (request = false)
The startup class must be placed under the java package, but under your com.xxxx package.
Thank you for reading this article carefully. I hope the article "how to report errors in xxxMapper injected with @ Autowired annotations" shared by the editor will be helpful to you. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
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.