Solve the Failed to load ApplicationContext error report in SpringBoot

Solve the Failed to load ApplicationContext error report in SpringBoot

1. Reason

There are basically a lot of reasons to see Caused byto know.

  1. 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.)
  2. Configuration files are linked to other classes. (Much more common in other classes using @PropertySource annotation, or @PropertySource not adding classpath:)
  3. 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)

Guess you like

Origin blog.csdn.net/YKenan/article/details/111320433