Solve problems when injected bean Springboot project unit test failure

Background to the issue:

The company recently built a project springboot project development, when the unit test, because after you build the project which may be produced by the project colleagues to test the file directory deleted, do not know when the project does not generate test directory generation needs its own to establish a test directory for testing. The red frame part is lower in FIG. . .

                                                                           

Problem Description:

After the test directory built the image above to write the test class life and death when injected into the bean unsuccessful, pay attention to this problem is not to consider issues such as version springboot

If you experience problems led springboot version of the bean class can not be injected into the project, and may be annotated version mismatch cause the scan springboot less than the corresponding bean class at startup class starts, this erroneous solution, a closed online a lot, not here in writing to the. . .

problem solved:

That is the test class package name and the package name must start classes the same package name must be the same! We must be consistent! Consistent! Important words three times! ! !

If the package were not, when you start the class do not know where to start scanning bean, so it can not be injected.

So here also give you an idea of ​​bean injection failed to solve:

1. First test to detect whether the package name and class name the same starting class package!

2. Check the notes and their own use is not consistent with the current version springboot.

3. Detection of whether the development of injection bean class code is normal, then gradually investigation according to the situation.

I hope to help you with any questions welcome message ~

---------- program is a step on the process to fill the pit with the pit and learn to enjoy the process -

 

Guess you like

Origin blog.csdn.net/it_erge/article/details/86605684