Solve the Failed to load ApplicationContext error report in SpringBoot
1. Reason
There are basically a lot of reasons to see
Caused by
to know.
- The imported package is not set in the configuration file. (It is mostly seen in the import database, but the dataSource is not configured in it; the scan bread is not added.)
- Configuration files are linked to other classes. (Much more common in other classes using @PropertySource annotation, or @PropertySource not adding
classpath:
)- Package conflict
2. Basic solution
Add in the test class:
Application.class is the name of the startup class.
@PropertySource(value = "classpath:application.properties")
@SpringBootTest(classes = {
Application.class}, webEnvironment = SpringBootTest.WebEnvironment.NONE)