In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article introduces how to solve the Springboot test class no bean injection problem, the content is very detailed, interested friends can refer to, I hope to help you.
Forget about other messy configurations, first put on the project structure diagram
After configuring the parameters, I tested the src/test/java class to access the database and found that the bean was not injected correctly. It is worth noting that the startup class for this project is called App.java
So we have to add comments to this test class:
@RunWith(SpringRunner.class)@SpringBootTest(classes = App.class)
Note: SpringBoot(classes = App.class) classes followed by the startup class, do not copy the configuration on the Internet, write some Application.class and the like, this Application class and some official package class names are the same, easy to introduce the wrong package.
At first, I found this problem. I went crazy to see how other people's configuration files were written on the Internet. It was useless after trying for a day. Later, I calmed down and copied the error message into the text to read it carefully.
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'com.springboot.LibrarySystem.mapper.UserMapperTest': Unsatisfied dependency expressed through field 'userMapper'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.sb.LibrarySystem.mapper.UserMapper' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
Or start with this Test class
My class was like this:
@RunWith(SpringRunner.class)@SpringBootTest(classes = Application.class)public class UserMapperTest {}
This is the same as the class name of my startup class:
@RunWith(SpringRunner.class)@SpringBootTest(classes = App.class)public class UserMapperTest {
Perfect solution!
If Baidu time, found that the problem is getting deeper and deeper, more and more deviated from the initial problem, then nine out of ten is the direction of the bias, reorganize it, start again
On how to solve the Springboot test class no bean injection problem to share here, I hope the above content can be of some help to everyone, you can learn more knowledge. If you think the article is good, you can share it so that more people can see it.
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.